kvarn::prelude::utils

Macro fmt_field

source
macro_rules! fmt_field {
    ($f: expr, $self:ident.$field:ident) => { ... };
    ($f: expr, $self:ident.$field:ident, $value:expr) => { ... };
}
Expand description

Adds a $field to the std::fmt::DebugStruct, $f from $self.

ยงExamples

use std::fmt::{self, Debug};
use kvarn_utils::{fmt_field, ident_str};
struct Foo {
    bar: u128,
    foobar: String,
}
impl Debug for Foo {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let mut s = f.debug_struct(ident_str!(Foo));
        fmt_field!(s, self.bar, &self.bar.to_le_bytes());
        fmt_field!(s, self.foobar);
        s.finish()
    }
}