Skip to main content

Mojo struct

Origin

@register_passable(trivial) struct Origin[mut: Bool]

This represents a origin reference for a memory value.

Parameters

  • mut (Bool): Whether the origin is mutable.

Implemented traits

AnyType, Copyable, ImplicitlyCopyable, Movable, UnknownDestructibility

Aliases

__copyinit__is_trivial

alias __copyinit__is_trivial = True

__del__is_trivial

alias __del__is_trivial = True

__moveinit__is_trivial

alias __moveinit__is_trivial = True

cast_from

alias cast_from[mut: Bool, //, o: Origin[mut]] = o._mlir_origin

Cast an existing Origin to be of the specified mutability.

This is a low-level way to coerce Origin mutability. This should be used rarely, typically when building low-level fundamental abstractions. Strongly consider alternatives before reaching for this "escape hatch".

Safety: This is an UNSAFE operation if used to cast an immutable origin to a mutable origin.

Examples:

Cast a mutable origin to be immutable:

struct Container[mut: Bool, //, origin: Origin[mut]]:
    var data: Int

    fn imm_borrow(self) -> Container[ImmutableOrigin.cast_from[origin]]:
        pass

Parameters

external

alias external = origin_of()

An external origin of the given mutability. The external origin is guaranteed not to alias any existing origins.

An external origin implies there is no previously existing value that this origin aliases. Therefore, the compiler cannot track the origin or the value's lifecycle. The external origin is useful when interfacing with memory that comes from outside the current Mojo program.

Was this page helpful?