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
,
Movable
,
UnknownDestructibility
Aliases
cast_from
alias cast_from = _lit_mut_cast[mut, ?]
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
alias empty = {}
An empty __origin_of()
of the given mutability. The empty origin is guaranteed not to alias any existing origins.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!