kvarn_utils::prelude::fmt

Struct DebugStruct

1.2.0 · source
pub struct DebugStruct<'a, 'b>
where 'b: 'a,
{ /* private fields */ }
Expand description

A struct to help with fmt::Debug implementations.

This is useful when you wish to output a formatted struct as a part of your Debug::fmt implementation.

This can be constructed by the Formatter::debug_struct method.

§Examples

use std::fmt;

struct Foo {
    bar: i32,
    baz: String,
}

impl fmt::Debug for Foo {
    fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
        fmt.debug_struct("Foo")
           .field("bar", &self.bar)
           .field("baz", &self.baz)
           .finish()
    }
}

assert_eq!(
    format!("{:?}", Foo { bar: 10, baz: "Hello World".to_string() }),
    r#"Foo { bar: 10, baz: "Hello World" }"#,
);

Implementations§

source§

impl<'a, 'b> DebugStruct<'a, 'b>
where 'b: 'a,

1.2.0 · source

pub fn field( &mut self, name: &