pub struct OptionalCell<T> { /* private fields */ }
Expand description

OptionalCell is a Cell that wraps an Option. This is helper type that makes keeping types that can be None a little cleaner.

Implementations

Create a new OptionalCell.

Create an empty OptionalCell (contains just None).

Update the stored value.

Insert the value of the supplied Option, or None if the supplied Option is None.

Replace the contents with the supplied value. If the cell was not empty, the previous value is returned, otherwise None is returned.

Reset the stored value to None.

Check if the cell contains something.

Check if the cell is None.

Returns true if the option is a Some value containing the given value.

Transforms the contained Option<T> into a Result<T, E>, mapping Some(v) to Ok(v) and None to Err(err).

Arguments passed to ok_or are eagerly evaluated; if you are passing the result of a function call, it is recommended to use ok_or_else, which is lazily evaluated.

Transforms the contained Option<T> into a Result<T, E>, mapping Some(v) to Ok(v) and None to Err(err).

Returns None if the option is None, otherwise returns optb.

Returns None if the option is None, otherwise calls predicate with the wrapped value and returns:

  • Some(t) if predicate returns true (where t is the wrapped value), and
  • None if predicate returns false.

Returns the option if it contains a value, otherwise returns optb.

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.

Returns the option if it contains a value, otherwise calls f and returns the result.

Return the contained value and replace it with None.

Returns the contained value or a default

Consumes the self argument then, if Some, returns the contained value, otherwise if None, returns the default value for that type.

Returns a copy of the contained Option.

Returns the contained value or panics if contents is None. We do not use the traditional name for this function – unwrap() – because the Tock kernel discourages panicking, and this name is intended to discourage users from casually adding calls to unwrap() without careful consideration.

Returns the contained value or a default.

Returns the contained value or computes a default.

Call a closure on the value if the value exists.

Call a closure on the value if the value exists, or return the default if the value is None.

If the cell contains a value, call a closure supplied with the value of the cell. If the cell contains None, call the other closure to return a default value.

If the cell is empty, return None. Otherwise, call a closure with the value of the cell and return the result.

Trait Implementations

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.