core::fmt::DebugStruct - Rust
Description: API documentation for the Rust `DebugStruct` struct in crate `core`.
Keywords: rust, rustlang, rust-lang, DebugStruct

# Struct core::fmt::DebugStruct 1.2.0 [−] [src]

    #[must_use]
    pub struct DebugStruct<'a, '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: 'a> DebugStruct<'a, 'b>`
[src]

#### `pub fn field(&mut self, name: &str, value: &Debug) -> &mut DebugStruct<'a, 'b>`
[src]

Adds a new field to the generated struct output.

#### `pub fn finish(&mut self) -> Result`
[src]

Finishes output and returns any error encountered.

# Help

## Keyboard Shortcuts

?
  Show this help dialog
S
  Focus the search field
↑
  Move up in search results
↓
  Move down in search results
↹
  Switch tab
⏎
  Go to active search result
+ / -
  Collapse/expand all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)