Skip to content

Commit bac931e

Browse files
authored
Merge pull request #1988 from LucaPaterlini/patch-2
Update supertraits.md
2 parents 7e1dfdb + ff712be commit bac931e

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

src/trait/supertraits.md

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,48 @@ fn comp_sci_student_greeting(student: &dyn CompSciStudent) -> String {
3434
)
3535
}
3636
37-
fn main() {}
37+
struct CSStudent {
38+
name: String,
39+
university: String,
40+
fav_language: String,
41+
git_username: String
42+
}
43+
44+
impl Programmer for CSStudent {
45+
fn fav_language(&self) -> String {
46+
self.fav_language.clone()
47+
}
48+
}
49+
50+
impl Student for CSStudent {
51+
fn university(&self) -> String {
52+
self.university.clone()
53+
}
54+
}
55+
56+
impl Person for CSStudent {
57+
fn name(&self) -> String {
58+
self.name.clone()
59+
}
60+
}
61+
62+
impl CompSciStudent for CSStudent {
63+
fn git_username(&self) -> String {
64+
self.git_username.clone()
65+
}
66+
}
67+
68+
fn main() {
69+
let student = CSStudent {
70+
name: String::from("Alice"),
71+
university: String::from("MIT"),
72+
fav_language: String::from("Rust"),
73+
git_username: String::from("alice_codes"),
74+
};
75+
76+
let greeting = comp_sci_student_greeting(&student);
77+
println!("{}", greeting);
78+
}
3879
```
3980

4081
### See also:

0 commit comments

Comments
 (0)