1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| #[derive(Debug)] struct User { name: String, age: u32, email: String } let email = String::from("a@b.com") let user = User { name: String::from("ac"), age: 27, email, } let user2 = User { name: String::from("ab"), ...user1 ...user1.clone() } user.name
struct Color(i32, i32, i32); let a = Color(0, 0, 0)
impl User { fn func1(&self) -> i32 { self.age + 10 } } user1.func1()
impl fmt::Display for MyStructure { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.0) } }
|