关于struct中String字段的问题不理解的地方,请明白人给讲解一下,万分感谢!!!
struct User {
active: bool,
username: String,
email: String,
sign_in_count: u64,
}
fn main() {
// –snip–
let user1 = User {
email: String::from("someone@example.com"),
username: String::from("someusername123"),
active: true,
sign_in_count: 1,
};
let user2 = User {
active: user1.active,
username: user1.username,
email: String::from("another@example.com"),
sign_in_count: user1.sign_in_count,
};
}
其中user2.username使用user1.username,致使user1.username变的不可用,但user1是不可变的,这是否违背了不可变变量的准则?
关于 LearnKu
推荐文章: