0Pricing
Mojo Academy · Lesson

Generic Functions over Traits

Write one function for many types.

One Function, Many Types

The real power of traits is generic code: write a function once and it works for every conforming type. 🚀

A Trait as a Bound

You use a trait as a bound on a generic parameter, promising the type has the methods you call.

All lessons in this course

  1. What Is a Trait?
  2. Conforming a Struct to a Trait
  3. Built-in Traits Like Copyable
  4. Generic Functions over Traits
← Back to Mojo Academy