Store trait. While native types (like felt252, u128, etc.) can be stored directly, custom types need this additional step to generate the necessary implementation on how to handle their storage.
To make a custom type storable:
- Derive the
starknet::Storetrait for your struct - Add any other necessary traits like
Drop,Serde, andCopy - Define your storage variables using the custom type
Person struct:
For more complex types, you might need to implement the
Store trait manually instead of deriving it.Accessing Struct Members
When you derive theStore trait, Cairo automatically generates the necessary storage pointers for each struct member. This allows you to access and modify individual fields of your stored struct directly: