1个不稳定版本
| 0.9.0 | 2023年6月5日 |
|---|
#25 在 #produce
5,093 每月下载量
在 6 个crate中使用 (通过 starlark)
12KB
215 行
提供实现Display的实用工具,同时也提供“替代”显示。
以下是一个使用这些组合器的示例
use std::fmt;
use display_container::*;
struct MyItems(Vec<(String, i32)>);
impl fmt::Display for MyItems {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt_container(f, "{", "}",
iter_display_chain(
&["magic"],
self.0.iter().map(|(k, v)| display_pair(k, "=", v))
)
)
}
}
会产生如下结果
{magic, hello=1, world=2}
对于“正常”显示,输出类似 (带有 prefix="prefix[", suffix="]")
prefix[] prefix[1] prefix[1, 2]
对于“替代”显示,输出类似
prefix[] prefix[ 1 ]
prefix[
1,
2
]
除了替代标志外,这不会在Formatter上传播其他标志。
依赖项
~66KB