0Pricing
Mojo Academy · Lesson

Conforming a Struct to a Trait

Implement the methods a trait demands.

Signing the Contract

A trait only describes behavior. To use it, a struct must conform by actually implementing the required methods. ✍️

Naming the Trait

You declare conformance by listing the trait in parentheses after the struct name, just like a parameter list.

struct Dog(Greetable):
    var name: String

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