File tree Expand file tree Collapse file tree 1 file changed +42
-1
lines changed
Expand file tree Collapse file tree 1 file changed +42
-1
lines changed Original file line number Diff line number Diff 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:
You can’t perform that action at this time.
0 commit comments