Los traits definen comportamiento compartido:
trait Describable { fn describe(self) -> str } struct Dog { name: str } impl Describable for Dog { fn describe(self) -> str { return "Perro: {self.name}" } }
Objetivo: Crea un trait Greet con método greet() e impleméntalo para la struct User.
Greet
greet()
User
Ejecuta el código para ver el output
9 resultados