Rust Tuesdays: Traits


Details
trait TraitsMastery {
fn attend(&self) -> bool;
fn gain_knowledge(&mut self, topics: Vec<&str>) -> bool;
}
struct RustDeveloper {
name: String,
traits_level: u8,
}
impl TraitsMastery for RustDeveloper {
fn attend(&self) -> bool {
true // πββοΈ Attending the FREE Rust Traits π οΈ Workshop!
}
fn gain_knowledge(&mut self, topics: Vec<&str>) -> bool {
println!("π§βπ« Learning about:");
for topic in topics {
println!(" β¨ {}", topic);
}
self.traits_level += 1;
true
}
}
fn main() {
let mut jane = RustDeveloper {
name: String::from("Jane Doe"),
traits_level: 1,
};
if jane.attend() {
jane.gain_knowledge(vec![
"Traits π",
"Defining & Implementing Traits π",
"Trait Bounds π",
"Inheriting Traits π§βπΌ",
"Static vs Dynamic Dispatch β‘οΈπ’",
"Operator Overloading β¨οΈ",
"Safe Abstractions π‘οΈ",
]);
println!("π₯³ {}'s Rust Traits Level: {}", jane.name, jane.traits_level);
}
}

Rust Tuesdays: Traits