Skip to content

Rust Tuesdays: Traits

Photo of Eric Manganaro
Hosted By
Eric M.
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);
}
}

Photo of Blockchain Center group
Blockchain Center
See more events
Station 3
26 Broadway 8th floor Β· New York, NY