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
- Before: Level 3: Ownership & Memory: Cairo Memory Model, References and Snapshots, Designing Safe Data Flow.
- Next: Level 5: Modules & Packages: Modules, Scarb, Package Organisation.
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.