Implement generic types and traits

Beginner
Developer
Student
Azure

Understand what generic types and traits are and how to use them in Rust.

Learning objectives

In this module, you'll learn:

  • What generic types are and how "wrapper" types use them.
  • What traits are and how they help us define shared behavior.
  • How to implement an existing trait for a custom type.
  • How to implement a custom trait for an existing type.
  • How trait bounds help us write generic functions.
  • How to implement an Iterator trait to iterate through collections.

Prerequisites

  • A solid understanding of Rust's types, ownerships, and moves. If you have any questions about those subjects, review the module Understand how Rust manages memory.