我有两个结构具有几乎相同的键。是否可以在不明确提及每个密钥的情况下复制所有密钥?有没有更清洁的方法可以做到这一点?
struct Type1<'a> {
field1: i32,
field2: &'a str,
field3: &'a str,
}
#[derive(Debug)]
struct Type2<'a> {
field1: i32,
field2: &'a str,
}
fn example() {
let t1 = Type1 {
field1: 1,
field2: "A",
field3: "B",
};
let t2 = Type2 {
field1: t1.field1,
field2: t1.field2,
};
println!("{:?}", t2);
}