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: StringAll lessons in this course
- What Is a Trait?
- Conforming a Struct to a Trait
- Built-in Traits Like Copyable
- Generic Functions over Traits