Mojo struct
Origin
@register_passable(trivial)
struct Origin[is_mutable: Bool]
This represents a origin reference for a memory value.
Parameters
- is_mutable (
Bool
): Whether the origin is mutable.
Aliases
-
cast_from = _lit_mut_cast[is_mutable, ?]
: 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].result]:
# ...struct Container[mut: Bool, //, origin: Origin[mut]]:
var data: Int
fn imm_borrow(self) -> Container[ImmutableOrigin.cast_from[origin].result]:
# ... -
empty = {}
: An empty__origin_of()
of the given mutability. The empty origin is guaranteed not to alias any existing origins.
Implemented traits
AnyType
,
Copyable
,
ExplicitlyCopyable
,
Movable
,
UnknownDestructibility
Methods
__init__
@implicit
__init__(mlir_origin: Origin[is_mutable.value]) -> Self
Initialize an Origin from a raw MLIR !lit.origin
value.
Args:
- mlir_origin (
Origin[is_mutable.value]
): The raw MLIR origin value.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!