Documentation Index
Fetch the complete documentation index at: https://docs.starknet.io/llms.txt
Use this file to discover all available pages before exploring further.
A trait for indexing operations (container[index]) where the input type is not modified.
container[index] is syntactic sugar for container.index(index).
Signature
Examples
The following example implements IndexView on a NucleotideCount container, which can be
indexed without modifying the input, enabling individual counts to be retrieved with index
syntax.
use core::ops::IndexView;
#[derive(Copy, Drop)]
enum Nucleotide {
A,
C,
G,
T,
}
#[derive(Copy, Drop)]
struct NucleotideCount {
a: usize,
c: usize,
g: usize,
t: usize,
}
impl NucleotideIndex of IndexView {
type Target = usize;
fn index(self: @NucleotideCount, index: Nucleotide) -> Self::Target {
match index {
Nucleotide::A => *self.a,
Nucleotide::C => *self.c,
Nucleotide::G => *self.g,
Nucleotide::T => *self.t,
}
}
}
let nucleotide_count = NucleotideCount {a: 14, c: 9, g: 10, t: 12};
assert!(nucleotide_count[Nucleotide::A] == 14);
assert!(nucleotide_count[Nucleotide::C] == 9);
assert!(nucleotide_count[Nucleotide::G] == 10);
assert!(nucleotide_count[Nucleotide::T] == 12);
Trait functions
index
Performs the indexing (container[index]) operation.
Panics
May panic if the index is out of bounds.
Signature
fn index(self: @C, index: I) -> IndexViewTarget
Trait types
Target
The returned type after indexing.
Signature