-
Notifications
You must be signed in to change notification settings - Fork 19
/
main.rs
48 lines (41 loc) · 1.05 KB
/
main.rs
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
// Write a program that creates a struct to represent a person with fields for name, age, and address, and implement methods to update the address.
#[allow(dead_code)]
struct Person {
name: String,
age: u8,
address: Address
}
#[allow(dead_code)]
#[derive(Debug)]
struct Address {
home_no: u8,
street: String,
city: String,
pincode: u32,
}
impl Person {
fn change_address(&mut self, new_address: Address) {
self.address = new_address;
println!("You have successfully changed your address to {:?}.", self.address);
}
}
fn main() {
let address: Address = Address {
home_no: 89,
street: "Jasmine".to_string(),
city: "Deskodia".to_string(),
pincode: 459234
};
let mut person: Person = Person {
name: "Steve".to_string(),
age: 34,
address
};
let new_address: Address = Address {
home_no: 23,
street: "Coriander".to_string(),
city: "Coleg".to_string(),
pincode: 190220
};
person.change_address(new_address);
}