Skip to main content

Mojo trait

Boolable

The Boolable trait describes a type that can be explicitly converted to a Bool or evaluated as a boolean expression in if or while conditions.

This trait requires the type to implement the __bool__() method. For example:

struct Foo(Boolable):
    var val: Bool

    fn __bool__(self) -> Bool:
        return self.val

Implemented traits

AnyType, UnknownDestructibility

Aliases

__del__is_trivial

alias __del__is_trivial

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

The implementation of __del__ is considered to be trivial if:

  • The struct has a compiler-generated trivial destructor and all its fields have a trivial __del__ method.

In practice, it means that the __del__ can be considered as no-op.

Methods

__bool__

__bool__(self: _Self) -> Bool

Get the boolean representation of the value.

Returns:

Bool: The boolean representation of the value.

Was this page helpful?