40 lines
893 B
Rust
40 lines
893 B
Rust
struct User {
|
|
username: String,
|
|
email: String,
|
|
sign_in_count: u64,
|
|
active: bool,
|
|
}
|
|
|
|
// Tuple Structs
|
|
struct Color(i32, i32, i32);
|
|
struct Point(i32, i32, i32);
|
|
|
|
fn main() {
|
|
let mut user1 = build_user(
|
|
String::from("someone@example.com"),
|
|
String::from("someusername123")
|
|
);
|
|
|
|
user1.email = String::from("anotheremail@example.com");
|
|
|
|
println!("Hello, {}, with email address: {}", user1.username, user1.email);
|
|
|
|
// Ooo... struct spread syntax...sort of
|
|
let user2 = User {
|
|
email: String::from("another@example.com"),
|
|
username: String::from("anotherusername567"),
|
|
..user1
|
|
};
|
|
|
|
println!("Hello, {}, with email address: {}", user2.username, user2.email);
|
|
}
|
|
|
|
fn build_user(email: String, username: String) -> User {
|
|
User {
|
|
email,
|
|
username,
|
|
active: true,
|
|
sign_in_count: 1,
|
|
}
|
|
}
|