Skip to content

Commit

Permalink
Added: Encoder for Box<dyn Display> and Box<dyn Error>
Browse files Browse the repository at this point in the history
  • Loading branch information
nurmohammed840 committed Jun 16, 2024
1 parent d5f32ec commit 4d9d129
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ members = ["databuf_derive", "databuf_derive_impl"]

[package]
name = "databuf"
version = "0.5.0"
version = "0.5.1"
edition = "2021"

license = "Apache-2.0"
Expand Down
14 changes: 14 additions & 0 deletions src/record/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@ macro_rules! impl_encoder_for {
}
impl_encoder_for!(str, String);

macro_rules! impl_encoder_for_trait_obj {
[$($ty:path),*] => {$(
impl Encode for Box<dyn $ty> {
#[inline]
fn encode<const CONFIG: u16>(&self, c: &mut (impl Write + ?Sized)) -> io::Result<()> {
let string = self.to_string();
encode_len!(string, c);
c.write_all(string.as_ref())
}
}
)*};
}
impl_encoder_for_trait_obj!(std::fmt::Display, std::error::Error);

macro_rules! read_slice {
[$c: expr] => ({
let len = decode_len!($c);
Expand Down

0 comments on commit 4d9d129

Please sign in to comment.