Cairo Custom Data Structures
Overview
Guide users through building mutable data structures on top of dictionaries and traits, including proper destruction.
Quick Use
- Read
references/custom-data-structures.mdbefore answering. - Emphasize that arrays are immutable; use
Felt252Dictfor mutable storage. - Call out
Destructimplementations for structs containing dictionaries.
Response Checklist
- Define a trait interface for the structure's operations.
- Store values in a
Felt252Dictand tracklenseparately when emulating vectors. - Use
Nullablewhen storing genericTin a dict. - Implement
Destructtosquash()dictionaries.
Example Requests
- "How do I build a mutable vector in Cairo?"
- "Why does my struct with a dictionary need Destruct?"
- "How can I update a value by index?"