Skip to content
Course map | Lesson 5 of 5

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

Global index

Find your way through Zolo

Try an idea

Start here

9 results

9 results

enespt-br