0Pricing
Mojo Academy · Lesson

What Is a Trait?

A contract of required methods.

Behavior You Can Share

Sometimes many types need the same ability, like being printable. A trait lets you describe that shared behavior once. 🤝

A Contract of Methods

Think of a trait as a contract: it lists the methods a type must provide, without saying how they work.

All lessons in this course

  1. What Is a Trait?
  2. Conforming a Struct to a Trait
  3. Built-in Traits Like Copyable
  4. Generic Functions over Traits
← Back to Mojo Academy