index
Indexing traits for indexing operations on collections. This module provides traits for implementing the indexing operator []
, offering two distinct approaches to access elements in collections: * IndexView
- For snapshot-based access * Index
- For reference-based access # When to use which trait - Use IndexView
when the collection can be accessed in a read-only context and is not mutated by a read access. This is the most common case in Cairo. - Use Index
when the input type needs to be passed as ref
. This is mainly useful for types depending on a Felt252Dict
, where dictionary accesses are modifying the data structure itself. Only one of these traits should be implemented for any given type, not both. Felt252Dict
: core::dict::Felt252Dict
Fully qualified path: core::ops::index