Skip to main content

Mojo trait

RegisterPassable

A marker trait to denote the type to be register passable.

The compiler treats the type that conforms to this trait with the following constraints:

  • the value struct doesn’t have “identity” - you can’t take the address of self on read convention methods. This is allows the compiler to pass it in registers.

  • The type implicitly conforms to Movable and the compiler synthesizes a trivial move constructor. The compiler needs to be able to move around values of the type by loading and storing them. A custom move constructor is not allowed.

  • Compiler checks that any stored member (vars) also conforms to this trait. It wouldn’t be possible to provide identity for a contained member if the container doesn’t have identity.

  • The type can choose whether it wants to be Copyable or not.

struct Foo(RegisterPassable):
   ...

Implemented traits

AnyType, Movable

comptime members

__move_ctor_is_trivial

comptime __move_ctor_is_trivial

A flag (often compiler generated) to indicate whether the implementation of move constructor is trivial.

The implementation of a move constructor is considered to be trivial if:

  • The struct has a compiler-generated trivial move constructor because all its fields have trivial move constructors.

In practice, it means the value can be moved by moving the bits from one location to another without side effects.

Required methods

__init__

__init__(out self: _Self, *, deinit take: _Self)

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

Args:

  • take (_Self): The value to move.

Returns:

_Self

Was this page helpful?