Cairo course

Cairo Level 4: Traits & Generics

Traits & Generics is level 4 of 14 of the LoWisa Cairo course. It has 3 lessons and 9 ideas. Below is every lesson and what it teaches, in one line each.

Updated 2026-11-30

Traits

  • Traits. A trait declares capability: functions a type promises: implemented in impl blocks.
  • impl blocks. An impl binds a trait to a type: named implementations selectable explicitly.
  • Derive. derive generates standard impls: Drop, Copy, Serde, PartialEq: one attribute, no boilerplate.

Generic Types

  • Generic functions. Functions take generic parameters with trait bounds: fn max<T, +PartialOrd<T>>.
  • Trait bounds. A bound demands capability of T: the plus syntax listing what the generic needs.
  • Monomorphisation. Generics compile per instantiation: abstraction without runtime dispatch cost.

Reusable Cairo Abstractions

  • Standard traits. The core library ships the shared traits: arithmetic, comparison, serialisation: implement them and join the ecosystem.
  • Generic containers. Generic structs build reusable containers: typed vaults and registries, proof-friendly.
  • Simplicity for provers. Every abstraction adds proving cost: Cairo design keeps the hot path humble.

Before and after this level

In the app each of these ideas is taught and then asked back, and the level ends with a checkpoint and flashcards. See Checkpoints and flashcards.

Frequently asked questions

What does Cairo Level 4: Traits & Generics cover?

Traits, Generic Types, Reusable Cairo Abstractions: 3 lessons and 9 ideas.

What should I know before this level?

The level before it, Level 3: Ownership & Memory, which covers Cairo Memory Model, References and Snapshots, Designing Safe Data Flow.

Learn Cairo on your phone

The first level is free. LoWisa is on Google Play and the App Store.