Skip to content

Commit 4561f0a

Browse files
committed
Error::write_fmt()
1 parent ef0bf25 commit 4561f0a

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

capnp/src/lib.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -400,9 +400,13 @@ pub enum ErrorKind {
400400
}
401401

402402
impl Error {
403-
#[cfg(feature = "alloc")]
404-
pub fn extra(&mut self, message: String) {
405-
self.extra = message;
403+
/// Writes to the `extra` field. Does nothing if the "alloc" feature is not enabled.
404+
pub fn write_fmt(&mut self, fmt: core::fmt::Arguments<'_>) {
405+
#[cfg(feature = "alloc")]
406+
{
407+
use core::fmt::Write;
408+
let _ = self.extra.write_fmt(fmt);
409+
}
406410
}
407411

408412
#[cfg(feature = "alloc")]

capnp/src/schema.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
//! Convenience wrappers of the datatypes defined in schema.capnp.
22
3-
#[cfg(feature = "alloc")]
4-
use alloc::string::ToString;
5-
63
use crate::dynamic_value;
74
use crate::introspect::{self, RawBrandedStructSchema, RawEnumSchema};
85
use crate::private::layout;
@@ -76,8 +73,7 @@ impl StructSchema {
7673
// error needs to be mutable only when the alloc feature is enabled
7774
#[allow(unused_mut)]
7875
let mut error = crate::Error::from_kind(crate::ErrorKind::FieldNotFound);
79-
#[cfg(feature = "alloc")]
80-
error.extra(name.to_string());
76+
write!(error, "{}", name);
8177
Err(error)
8278
}
8379
}

0 commit comments

Comments
 (0)