当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Rust DebugStruct.finish_non_exhaustive用法及代码示例


本文简要介绍rust语言中 alloc::fmt::DebugStruct.finish_non_exhaustive 的用法。

用法

pub fn finish_non_exhaustive(&mut self) -> Result<(), Error>

将结构标记为非详尽的,向读者表明调试表示中未显示一些其他字段。

例子

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() // Show that some other field(s) exist.
    }
}

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

相关用法


注:本文由纯净天空筛选整理自rust-lang.org大神的英文原创作品 alloc::fmt::DebugStruct.finish_non_exhaustive。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。