Option related operations.
Signature
Trait functions
expect
Returns the containedSome value, consuming the self value.
Signature
Panics
Panics if the option value isNone with a custom felt252 panic message err.
Examples
unwrap
Returns the containedSome value, consuming the self value.
Signature
Panics
Panics if theself value equals None.
Examples
ok_or
Transforms theOption into a Result, mapping Some(v) to
Ok(v) and None to Err(err).
Signature
Examples
ok_or_else
Transforms theOption into a Result, mapping Some(v) to
Ok(v) and None to Err(err()).
Signature
Examples
and
ReturnsNone if the option is None, otherwise returns optb.
Arguments passed to and are eagerly evaluated; if you are passing the
result of a function call, it is recommended to use and_then, which is
lazily evaluated.
Signature
Examples
and_then
ReturnsNone if the option is None, otherwise calls f with the
wrapped value and returns the result.
Some languages call this operation flatmap.
Signature
Examples
or
Returns the option if it contains a value, otherwise returnsoptb.
Arguments passed to or are eagerly evaluated; if you are passing the
result of a function call, it is recommended to use or_else, which is
lazily evaluated.
Signature
Examples
or_else
Returns the option if it contains a value, otherwise callsf and
returns the result.
Signature
Examples
xor
ReturnsSome if exactly one of self, optb is Some, otherwise returns None.
Signature
Examples
is_some
Returnstrue if the Option is Some, false otherwise.
Signature
Examples
is_some_and
Returnstrue if the Option is Some and the value inside of it matches a
predicate.
Signature
Examples
is_none
Returnstrue if the Option is None, false otherwise.
Signature
Examples
is_none_or
Returnstrue if the Option is None or the value inside of it matches a
predicate.
Signature
Examples
unwrap_or
Returns the containedSome value if self is Some(x). Otherwise, returns the
provided default.
Signature
Examples
unwrap_or_default
Returns the containedSome value if self is Some(x). Otherwise, returns
Default::::default().
Signature
Examples
unwrap_or_else
Returns the containedSome value or computes it from a closure.
Signature
Examples
map
Maps anOption to Option by applying a function to a contained value (if Some)
or returns None (if None).
Signature
Examples
map_or
Returns the provided default result (if none), or applies a function to the contained value (if any). Arguments passed tomap_or are eagerly evaluated; if you are passing
the result of a function call, it is recommended to use map_or_else,
which is lazily evaluated.
Signature
Examples
map_or_else
Computes a default function result (if none), or applies a different function to the contained value (if any).Signature
Examples
take
Takes the value out of the option, leaving aNone in its place.
Signature
Examples
filter
ReturnsNone if the option is None, otherwise calls predicate
with the wrapped value and returns:
Some(t)ifpredicatereturnstrue(wheretis the wrapped value), andNoneifpredicatereturnsfalse.
Signature
Examples
flatten
Converts fromOption> to Option.