2个不稳定版本
0.2.0 | 2022年4月7日 |
---|---|
0.1.0 | 2022年3月31日 |
#21 in #shortcuts
每月 283 次下载
在 you-must-conform 中使用
24KB
540 行
generic-new
一个衍生宏,为某些类型生成具有快捷键的易用构造函数。
use generic_new::GenericNew;
#[derive(GenericNew)]
struct Foo {
s: String, // -> impl AsRef<str>
v: Vec<usize>, // -> impl IntoIterator<Item = usize>
i: Vec<String>, // -> impl IntoIterator<Item = impl AsRef<str>>
p: PathBuf, // -> impl AsRef<Path>
#[generic_new(ignore)]
o: String, // Turn off magic conversion for some fields
#[generic_new(ty = impl Into<usize>, converter = |u|Into::into(u))]
u: usize, // Custom converters are supported
}
Foo::new(
"hello",
[1, 2, 3],
["a", "b", "c"],
"path/to/foo",
String::from("world"),
1u16,
);
许可证: MIT
依赖项
~4–13MB
~140K SLoC