Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion src/trait/supertraits.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,48 @@ fn comp_sci_student_greeting(student: &dyn CompSciStudent) -> String {
)
}

fn main() {}
struct CSStudent {
name: String,
university: String,
fav_language: String,
git_username: String
}

impl Programmer for CSStudent {
fn fav_language(&self) -> String {
self.fav_language.clone()
}
}

impl Student for CSStudent {
fn university(&self) -> String {
self.university.clone()
}
}

impl Person for CSStudent {
fn name(&self) -> String {
self.name.clone()
}
}

impl CompSciStudent for CSStudent {
fn git_username(&self) -> String {
self.git_username.clone()
}
}

fn main() {
let student = CSStudent {
name: String::from("Alice"),
university: String::from("MIT"),
fav_language: String::from("Rust"),
git_username: String::from("alice_codes"),
};

let greeting = comp_sci_student_greeting(&student);
println!("{}", greeting);
}
```

### See also:
Expand Down