Options
bevy.options.Option
Bases: Generic[_T]
, ABC
Option
types help make code cleaner and typing more consistent. The Value
option wraps values while the Null
options stand in for no value. Option
types are convenient to use with match/case statements.
Example
match result:
case Value(value):
...
case Null():
...
value
abstractmethod
property
value: _T
Returns the value assigned to the option. This raises Exception
if accessed on a Null
option.
value_or
abstractmethod
value_or(default: _T) -> _T
Returns the value if it is set, otherwise returns the provided default value.
bevy.options.Value
Value(value: _T)
Bases: Option[_T]
The Value
option type is used to wrap a value. No matter what the value a Value
option always evaluates as
True
to help identify if an Option
has a value set. The Value
option can surface its value as a match arg in a
match/case statement.
Example
match example:
case Value(value):
print(value)
value
property
value: _T
Gets the value assigned to the Value
option.
value_or
value_or(default: _T) -> _T
Value
option always have a value set, this always returns that value.
bevy.options.Null
Null(message: str = '')
Bases: Option
The Null
option type represents the absence of a value. The Null
option will always evaluate as False
to
help identify if an Option
has a value or not. Null
options can take an optional message that will be used in
error messages and that can be surfaced as a match arg in match/case statements.
Example
match example:
case Null(message):
print(message)
message
property
message: str
The exception message the Null
option will use if the value is accessed.
value
property
value
The Null
options never have values so this raises an Exception
containing the Null
option's message.
value_or
value_or(default: _T) -> _T
Null
options never have a value so this only returns default
.