Skip to main content

Mojo struct

Pointer

Defines a non-nullable safe pointer.

Parameters

  • is_mutable (Bool): Whether the pointee data may be mutated through this.
  • type (AnyType): Type of the underlying data.
  • origin (Origin[is_mutable.value]): The origin of the pointer.
  • address_space (AddressSpace): The address space of the pointee data.

Implemented traits

AnyType, CollectionElementNew, Copyable, ExplicitlyCopyable, Movable, Stringable

Methods

__init__

__init__(out self, *, other: Self)

Constructs a copy from another Pointer.

Note that this does not copy the underlying data.

Args:

  • other (Self): The Pointer to copy.

__getitem__

__getitem__(self) -> ref [origin, address_space] type

Enable subscript syntax ptr[] to access the element.

Returns:

A reference to the underlying value in memory.

__eq__

__eq__(self, rhs: Pointer[type, origin, address_space]) -> Bool

Returns True if the two pointers are equal.

Args:

  • rhs (Pointer[type, origin, address_space]): The value of the other pointer.

Returns:

True if the two pointers are equal and False otherwise.

__ne__

__ne__(self, rhs: Pointer[type, origin, address_space]) -> Bool

Returns True if the two pointers are not equal.

Args:

  • rhs (Pointer[type, origin, address_space]): The value of the other pointer.

Returns:

True if the two pointers are not equal and False otherwise.

address_of

static address_of(ref [origin, address_space] value: type) -> Self

Constructs a Pointer from a reference to a value.

Args:

  • value (type): The value to get the address of.

Returns:

The result Pointer.

__str__

__str__(self) -> String

Gets a string representation of the Pointer.

Returns:

The string representation of the Pointer.