Skip to main content

struct

OptionalReg

A register-passable optional type.

This struct optionally contains a value. It only works with trivial register passable types at the moment.

Parameters

  • T (AnyTrivialRegType): The type of value stored in the Optional.

Implemented traits

AnyType, Boolable

Methods

__init__

__init__(inout self: Self)

Create an optional with a value of None.

__init__(inout self: Self, value: T)

Create an optional with a value.

Args:

  • value (T): The value.

__init__(inout self: Self, value: None)

Create an optional without a value from a None literal.

Args:

  • value (None): The None value.

__bool__

__bool__(self: Self) -> Bool

Return true if the optional has a value.

Returns:

True if the optional has a value and False otherwise.

__is__

__is__(self: Self, other: None) -> Bool

Return True if the Optional has no value.

It allows you to use the following syntax: if my_optional is None:

Args:

  • other (None): The value to compare to (None).

Returns:

True if the Optional has no value and False otherwise.

__isnot__

__isnot__(self: Self, other: None) -> Bool

Return True if the Optional has a value.

It allows you to use the following syntax: if my_optional is not None:

Args:

  • other (None): The value to compare to (None).

Returns:

True if the Optional has a value and False otherwise.

value

value(self: Self) -> T

Get the optional value.

Returns:

The contained value.