kvarn_utils

Macro fmt_fields

source
macro_rules! fmt_fields {
    ($f: expr, $($(#[$meta:meta])?($self:ident.$field:ident $(, $value:expr)?)),+ $(,)?) => { ... };
}
Expand description

fmt_field! but multiple.

ยงExamples

use std::fmt::{self, Debug};
use kvarn_utils::{fmt_fields, ident_str};
struct Foo {
    bar: u128,
    foo: u32,
    #[cfg(feature = "foobar")]
    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_fields!(
            s,
            (self.bar, &self.bar.to_le_bytes()),
            (self.foo),
            #[cfg(feature = "foobar")]
            (self.foobar),
        );
        s.finish()
    }
}