Structs and Enums
- Structs. A struct groups named fields: instantiated by name, destructured by pattern.
- Enums. An enum declares variants that may carry data: Option and Result are enums like yours.
- Generic types. Types take generic parameters: Wallet<T>: checked at compile time.
Pattern Matching
- match exhaustively. match handles every variant or fails to compile: the missing case is an error, forever.
- Destructuring. Patterns destructure structs and enums: fields bound as they match.
- Options and results. Option and Result are matched, mapped and propagated: absence and failure as values.
Collections
- Arrays. A Cairo array is append-only: written once, read by index, the prover-friendly sequence.
- Felt252Dict. The dictionary type gives key-value storage in memory: squashed and verified at run’s end.
- Spans. A span is a read-only view over an array: passing data without copying it.
Before and after this level
- Before: Level 1: Cairo Foundations: Values and Types, Functions, Control Flow.
- Next: Level 3: Ownership & Memory: Cairo Memory Model, References and Snapshots, Designing Safe Data Flow.
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 2: Data Structures cover?
Structs and Enums, Pattern Matching, Collections: 3 lessons and 9 ideas.
What should I know before this level?
The level before it, Level 1: Cairo Foundations, which covers Values and Types, Functions, Control Flow.