Struct std::fmt::DebugStruct 1.2.0
[−]
[src]
#[must_use]pub struct DebugStruct<'a, 'b> where
'b: 'a, { /* fields omitted */ }
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() } } // prints "Foo { bar: 10, baz: "Hello World" }" println!("{:?}", Foo { bar: 10, baz: "Hello World".to_string() });Run
Methods
impl<'a, 'b> DebugStruct<'a, 'b> where
'b: 'a,
[src]
impl<'a, 'b> DebugStruct<'a, 'b> where
'b: 'a,
pub fn field(&mut self, name: &str, value: &Debug) -> &mut DebugStruct<'a, 'b>
[src]
pub fn field(&mut self, name: &str, value: &Debug) -> &mut DebugStruct<'a, 'b>
Adds a new field to the generated struct output.
pub fn finish(&mut self) -> Result<(), Error>
[src]
pub fn finish(&mut self) -> Result<(), Error>
Finishes output and returns any error encountered.
Trait Implementations
Auto Trait Implementations
impl<'a, 'b> !Send for DebugStruct<'a, 'b>
impl<'a, 'b> !Send for DebugStruct<'a, 'b>
impl<'a, 'b> !Sync for DebugStruct<'a, 'b>
impl<'a, 'b> !Sync for DebugStruct<'a, 'b>