Struct std::fmt::DebugSet1.2.0[][src]

#[must_use = "must eventually call `finish()` on Debug builders"]
pub struct DebugSet<'a, 'b> where
    'b: 'a, 
{ /* fields omitted */ }
Expand description

一个有助于 fmt::Debug 实现的结构体。

当您希望输出格式化的项集作为 Debug::fmt 实现的一部分时,这很有用。

这可以通过 Formatter::debug_set 方法创建。

Examples

use std::fmt;

struct Foo(Vec<i32>);

impl fmt::Debug for Foo {
    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
        fmt.debug_set().entries(self.0.iter()).finish()
    }
}

assert_eq!(
    format!("{:?}", Foo(vec![10, 11])),
    "{10, 11}",
);
Run

Implementations

将新条目添加到设置的输出中。

Examples

use std::fmt;

struct Foo(Vec<i32>, Vec<u32>);

impl fmt::Debug for Foo {
    fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
        fmt.debug_set()
           .entry(&self.0) // 添加第一个 "entry"。
           .entry(&self.1) // 添加第二个 "entry"。
           .finish()
    }
}

assert_eq!(
    format!("{:?}", Foo(vec![10, 11], vec![12, 13])),
    "{[10, 11], [12, 13]}",
);
Run

将条目迭代器的内容添加到设置的输出中。

Examples

use std::fmt;

struct Foo(Vec<i32>, Vec<u32>);

impl fmt::Debug for Foo {
    fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
        fmt.debug_set()
           .entries(self.0.iter()) // 添加第一个 "entry"。
           .entries(self.1.iter()) // 添加第二个 "entry"。
           .finish()
    }
}

assert_eq!(
    format!("{:?}", Foo(vec![10, 11], vec![12, 13])),
    "{10, 11, 12, 13}",
);
Run

完成输出并返回遇到的任何错误。

Examples

use std::fmt;

struct Foo(Vec<i32>);

impl fmt::Debug for Foo {
    fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
        fmt.debug_set()
           .entries(self.0.iter())
           .finish() // 结束结构体格式化。
    }
}

assert_eq!(
    format!("{:?}", Foo(vec![10, 11])),
    "{10, 11}",
);
Run

Auto Trait Implementations

Blanket Implementations

获取 selfTypeIdRead more

从拥有的值中一成不变地借用。 Read more

从拥有的值中借用。 Read more

执行转换。

执行转换。

发生转换错误时返回的类型。

执行转换。

发生转换错误时返回的类型。

执行转换。