Data Structures · 4.5
Traits
All lessons are open — jump whenever you need.
Traits define shared behavior:
trait Describable {
fn describe(self) -> str
}
struct Dog { name: str }
impl Describable for Dog {
fn describe(self) -> str {
return "Dog: {self.name}"
}
}Goal: Create a trait Greet with a greet() method and implement it for struct User.
lesson-4-5.zolo
Program output
Run the code to see the output