Introduction
A trait is a collection of methods defined for an unknown type: Self. They can access other methods declared in the same trait.Traits can be implemented for any data type.
Rust’Trait is like Java’Interface.
- Derive
- Operator Overloading
- Drop
- Iterators
- Clone
Example
Case: Hello
1 | struct Sheep { naked: bool, name: &'static str } |
1 | Dolly pauses briefly... baaaaah! |