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


Rust Formatter.fill用法及代码示例


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

用法

pub fn fill(&self) -> char

对齐时用作'fill' 的字符。

例子

use std::fmt;

struct Foo;

impl fmt::Display for Foo {
    fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
        let c = formatter.fill();
        if let Some(width) = formatter.width() {
            for _ in 0..width {
                write!(formatter, "{}", c)?;
            }
            Ok(())
        } else {
            write!(formatter, "{}", c)
        }
    }
}

// We set alignment to the right with ">".
assert_eq!(&format!("{:G>3}", Foo), "GGG");
assert_eq!(&format!("{:t>6}", Foo), "tttttt");

相关用法


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