4个版本
0.0.4 | 2021年12月20日 |
---|---|
0.0.3 | 2021年12月20日 |
0.0.2 | 2021年12月12日 |
0.0.1 | 2021年12月12日 |
在进程宏中排名第1150
8KB
68 行
Lib3d6
这是我的Rust实用程序库,有很多类似的库,几乎在所有方面都更优秀,但这是属于我的。
目前它是一个玩具项目,因为我正在重新学习这门语言。
F-字符串打印
Python打印很酷,在Rust中实现它相当简单。
警告:当前实现是WIP,它工作,但肯定有错误,效率低下,有些难看。
// Importing is kind of ugly, looking for help making it better
// `*` import leads to ambiguity, and I can't get an import macro working
use lib3d6::{format, print, println};
let v1 = ("arga", "barga", 33);
let v2 = 121421;
let v3: f32 = 32.12;
let v4: &str = "Ahhha";
let v5 = ["1", "2", "three"];
let v6 = "have".to_owned();
let v7 = Some("tea");
assert_eq!(
// Overrides format to support f-string
format!(f"This is {v7}"),
// Ugly old format still works
format!("This is {:?}", v7)
);
// Same thing happens with print and println
println!(f"{v5} {v6} {v7}");
print!(f"It can work with any object of a type that implements the Debug trait, such as this tuple: {v1}\n");
print!(f"But also with primitives like v3 ({v3}), and it handles duplicates: {v4}, {v4}, {v4}");
println!("\nBut as always, {} still {:?}", "the old way of doing things", "works");