> ## 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.

# core::ops::index::IndexView

A trait for indexing operations (`container[index]`) where the input type is not modified.
`container[index]` is syntactic sugar for `container.index(index)`.

## Signature

```rust theme={null}
pub trait IndexView
```

## 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.

```rust theme={null}
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

```rust theme={null}
fn index(self: @C, index: I) -> IndexViewTarget
```

## Trait types

### Target

The returned type after indexing.

#### Signature

```rust theme={null}
type Target;
```
