typed-builder,创建经过编译时验证的构建器,发布了v0.5.0版本。示例:
#[macro_use]
extern crate typed_builder;
#[derive(TypedBuilder)]
struct Foo {
// Mandatory Field:
x: i32,
// #[builder(default)] without parameter - use the type's default
// #[builder(setter(strip_option))] - wrap the setter argument with `Some(...)`
#[builder(default, setter(strip_option))]
y: Option<i32>,
// Or you can set the default
#[builder(default=20)]
z: i32,
}
Foo::builder().x(1).y(2).z(3).build();
Foo::builder().z(1).x(2).y(3).build();
Foo::builder().x(1).build();
Foo::builder().build(); // missing x
Foo::builder().x(1).y(2).y(3); // y is specified twice
crate地址
RtcSms,用来发送短信报告下一辆公交车到达前所剩余的时间。
Github
format!
宏旨在使那些使用C语言的printf/fprintf
函数或Python语言的str.format
函数的用户提供熟悉格式化方法。
format!("Hello"); // => "Hello"
format!("Hello, {}!", "world"); // => "Hello, world!"
format!("The number is {}", 1); // => "The number is 1"
format!("{:?}", (3, 4)); // => "(3, 4)"
format!("{value}", value=4); // => "4"
format!("{} {}", 1, 2); // => "1 2"
format!("{:04}", 42); // => "0042" with leading zeros
使用文档