Step Into Rust · Lesson 5 · Ownership & Types
Traits & Generics
Shared behavior with traits, generic functions, trait objects and the standard traits.
- ~40 minreading and coding
- 5missions
- membersaccess
- Rustlanguage
Part of Step Into Rust. The full lesson, its missions and the real compiler and debugger are in the course. Try a free lesson first to see how it works.
A trait is a set of methods a type promises to have. It is Rust's version of an interface:
In this lesson
- Traits: what a type can do
- Generics: one function, many types
- Trait objects: different types in one list
- The standard traits you will implement most
Missions
- Your first trait
- A default method
- A generic function
- Trait objects
- Display and derive