Rust 中使用 struct 关键字定义并实例化结构体。
示例程序:
struct User {
username: String,
email: String,
sign_in_count: u64,
actice: bool,
}
fn main() {
let user1 = User {
username: String::from("yuyoubei"),
email: String::from("yuyoubei@qq.com"),
actice: true,
sign_in_count: 123,
};
println!("{}, {}, {}, {}", user1.username, user1.email, user1.actice, user1.sign_in_count); // 输出 yuyoubei, yuyoubei@qq.com, true, 123
}