Skip to main content
A trait for indexing operations (container[index]) where the input type is mutated. This trait should be implemented when you want to implement indexing operations on a type that’s mutated by a read access. This is useful for any type depending on a Felt252Dict, where dictionary accesses are modifying the data structure itself. container[index] is syntactic sugar for container.index(index).

Signature

Examples

The following example implements Index on a Stack type. This Stack is implemented based on a Felt252Dict, where dictionary accesses are modifying the dictionary itself. As such, we must implement the Index trait instead of the IndexView trait.

Trait functions

index

Performs the indexing (container[index]) operation.

Panics

May panic if the index is out of bounds.

Signature

Trait types

Target

The returned type after indexing.

Signature