Skip to content
← Index | Lesson 5 of 5

Traits

Traits in Zolo

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

Search Zolo

9 results

enespt-br