std::fmt::DebugStruct - Rust (original) (raw)

Struct std::fmt::DebugStruct1.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 yourDebug::fmt implementation.

This can be constructed by theFormatter::debug_structmethod.

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() } }

println!("{:?}", Foo { bar: 10, baz: "Hello World".to_string() });Run

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

'b: 'a, `[src]

pub fn [field](#method.field)(&mut self, name: &[str](../primitive.str.html), value: &[Debug](../../std/fmt/trait.Debug.html "trait std::fmt::Debug")) -> &mut [DebugStruct](../../std/fmt/struct.DebugStruct.html "struct std::fmt::DebugStruct")<'a, 'b>[src]

Adds a new field to the generated struct output.

pub fn [finish](#method.finish)(&mut self) -> [Result](../../std/result/enum.Result.html "enum std::result::Result")<[()](../primitive.unit.html), [Error](../../std/fmt/struct.Error.html "struct std::fmt::Error")>[src]

Finishes output and returns any error encountered.