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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#[derive(Debug)]
struct User {
username: String,
email: String,
sign_in_count: u64,
active: bool,
}
#[derive(Debug)]
struct Rect {
width: u32,
height: u32,
}
impl Rect {
fn area(&self) -> u32 {
self.width * self.height
}
fn in_area(&self, other: &Rect) -> bool {
self.width > other.width && self.height > other.height
}
}
fn area(rect: &Rect) -> u32 {
rect.width * rect.height
}
fn main () {
let rect = Rect {
width: 30,
height: 50,
};
println!("The area of the rectangle is {} square pixels.", area(&rect));
println!("The size of the rectangle is {} square pixels.", rect.area());
let rect2 = Rect {
width: 10,
height: 40,
};
println!("rect2 in rect? {}", rect.in_area(&rect2));
// let mut user = User {
// email: String::from("abc@123.com"),
// username: String::from("abc"),
// active: true,
// sign_in_count: 1,
// };
// println!("{:#?}", user);
// user.email = String::from("abc@zhihu.com");
// println!("{:#?}", user);
// let user1 = User {
// email: String::from("user@abc.com"),
// ..user
// };
// println!("{:#?}", user1);
}
struct Color(i32, i32, i32);
struct Point(i32, i32, i32);