Cairo References and Snapshots
Overview
Explain when to pass by value, snapshot, or mutable reference, and how to read or mutate safely.
Quick Use
- Read
references/references-snapshots.mdbefore answering. - Show the correct parameter form (
value,@value, orref value). - Use
*snapshotonly forCopytypes.
Response Checklist
- Use snapshots (
@T) to read without moving ownership. - Use
refwhen the callee must mutate and the caller must regain ownership. - Remind that
refrequires amutvariable at the call site. - Call out that snapshots are immutable and cannot be mutated directly.
Example Requests
- "Why does passing this array move ownership?"
- "How do I modify a struct inside a function and keep it?"
- "What does
@mean in a type annotation?"