@@ -15,19 +15,19 @@ struct Person {
1515}
1616
1717impl Person {
18- pub fn new(name: String , age: u32) -> Self {
18+ pub fn new(name: &str , age: u32) -> Self {
1919 Person {
20- name,
20+ name: name.to_string() ,
2121 age
2222 }
2323 }
2424}
2525
2626fn main() {
2727 let mut people = vec![
28- Person::new("Zoe".to_string() , 25),
29- Person::new("Al".to_string() , 60),
30- Person::new("John".to_string() , 1),
28+ Person::new("Zoe", 25),
29+ Person::new("Al", 60),
30+ Person::new("John", 1),
3131 ];
3232
3333 // Sort people by derived natural order (Name and age)
@@ -36,9 +36,9 @@ fn main() {
3636 assert_eq!(
3737 people,
3838 vec![
39- Person::new("Al".to_string() , 60),
40- Person::new("John".to_string() , 1),
41- Person::new("Zoe".to_string() , 25),
39+ Person::new("Al", 60),
40+ Person::new("John", 1),
41+ Person::new("Zoe", 25),
4242 ]);
4343
4444 // Sort people by age
@@ -47,9 +47,9 @@ fn main() {
4747 assert_eq!(
4848 people,
4949 vec![
50- Person::new("Al".to_string() , 60),
51- Person::new("Zoe".to_string() , 25),
52- Person::new("John".to_string() , 1),
50+ Person::new("Al", 60),
51+ Person::new("Zoe", 25),
52+ Person::new("John", 1),
5353 ]);
5454
5555}
0 commit comments