Skip to main content
Log in

Mojo trait

Indexer

The Indexer trait is used for types that can index into a collection or pointer. The type returned is the underlying __mlir_type.index, enabling types like UInt to not have to be converted to an Int first. This type is implicitly convertable to an Int, so can be used anywhere an Int can e.g. for comparisons.

Implemented traits

AnyType, CollectionElement, Copyable, Intable, Movable, UnknownDestructibility

Methods

__copyinit__

__copyinit__(out self: _Self, existing: _Self, /)

Create a new instance of the value by copying an existing one.

Args:

  • existing (_Self): The value to copy.

__moveinit__

__moveinit__(out self: _Self, owned existing: _Self, /)

Create a new instance of the value by moving the value of another.

Args:

  • existing (_Self): The value to move.

__index__

__index__(self: _Self) -> index

Convert to index.

Returns:

The corresponding __mlir_type.index value.

__int__

__int__(self: _Self) -> Int

Get the integral representation of the value.

Returns:

The integral representation of the value.