2 个不稳定版本
0.2.0 | 2022 年 1 月 30 日 |
---|---|
0.1.0 | 2022 年 1 月 30 日 |
#9 在 #derivable
每月 25 次下载
9KB
111 行
新可推导
自动为您的基本结构(无名称和有名称)创建新的 new
实现。
use new_derivable::New;
#[derive(New,Debug)]
pub struct Human {
pub name: String,
pub age: i64
}
将创建
impl Human {
fn new(name: String, age: i64) -> Self {
Self { name, age }
}
}
然后您可以执行
fn main() {
let human = Human::new(String::from("Justin"),69);
println!("{:#?}", human);
}
这将给我们
Human {
name: "Justin",
age: 69
}
依赖关系
~2MB
~44K SLoC