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.
Greet
greet()
User
Run the code to see the output
9 results