A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://doc.rust-lang.org/nightly/core/fmt/struct.DebugStruct.html below:

DebugStruct in core::fmt - Rust

Struct DebugStruct1.6.0 · Source
pub struct DebugStruct<'a, 'b: 'a> {  }
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" }"#,
);
Source§ 1.2.0 · Source

Adds a new field to the generated struct output.

§Examples
use std::fmt;

struct Bar {
    bar: i32,
    another: String,
}

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

assert_eq!(
    format!("{:?}", Bar { bar: 10, another: "Hello World".to_string() }),
    r#"Bar { bar: 10, another: "Hello World", nonexistent_field: 1 }"#,
);
Source 🔬This is a nightly-only experimental API. (debug_closure_helpers #117729)

Adds a new field to the generated struct output.

This method is equivalent to DebugStruct::field, but formats the value using a provided closure rather than by calling Debug::fmt.

1.53.0 · Source

Marks the struct as non-exhaustive, indicating to the reader that there are some other fields that are not shown in the debug representation.

§Examples
use std::fmt;

struct Bar {
    bar: i32,
    hidden: f32,
}

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

assert_eq!(
    format!("{:?}", Bar { bar: 10, hidden: 1.0 }),
    "Bar { bar: 10, .. }",
);
1.2.0 · Source

Finishes output and returns any error encountered.

§Examples
use std::fmt;

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

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

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

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4