Step Into Labs

Step Into Rust · Lesson 5 · Ownership & Types

Traits & Generics

Shared behavior with traits, generic functions, trait objects and the standard traits.

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

Missions

  1. Your first trait
  2. A default method
  3. A generic function
  4. Trait objects
  5. Display and derive