logos.lang.option

Module lang · package logos-lang

Types

enumOption

enum Option

Represents an optional value: either Some(T) or None.

Implements: Eq IntoIterator Default Debug

Variants

None
Some(T)

Methods

fn and(self: Option, optb: Option) -> Option

Returns None if self is None, otherwise returns optb.

fn and_then(self: Option, f: fn(T) -> Option) -> Option

Returns None if self is None, otherwise applies f to the wrapped value.

fn as_mut(self: &mut Option) -> Option

Converts &mut Option<T> to Option<&mut T>.

fn as_ref(self: &Option) -> Option

Converts &Option<T> to Option<&T>.

fn expect(self: Option, msg: &[u8]) -> T

Returns the contained Some value. Panics with msg if the value is None.

fn filter(self: Option, pred: fn(T) -> bool) -> Option

Returns Some(v) if self is Some(v) and pred(v) is true, otherwise None. pred receives the wrapped value by bitwise copy; the original is returned untouched.

fn flatten(self: Option) -> Option

Flattens Option<Option<T>> into Option<T>.

fn is_none(self: &Option) -> bool

Returns true if the option is a None value.

fn is_some(self: &Option) -> bool

Returns true if the option is a Some value.

fn is_some_and(self: Option, pred: fn(T) -> bool) -> bool

Returns true iff the option is Some and pred accepts the wrapped value.

fn map(self: Option, f: fn(T) -> U) -> Option

Maps Option<T> to Option<U> by applying f to a contained value.

fn map_or(self: Option, default: U, f: fn(T) -> U) -> U

Returns default if None, otherwise applies f to the contained value.

fn map_or_else(self: Option, dfl: fn() -> U, f: fn(T) -> U) -> U

Computes a result from dfl if None, otherwise applies f to the contained value.

fn ok_or(self: Option, err: E) -> Result

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

fn ok_or_else(self: Option, err: fn() -> E) -> Result

Transforms into Result<T, E> like ok_or, computing the error lazily from err.

fn or(self: Option, other: Option) -> Option

Returns self if it contains a value, otherwise returns other.

fn or_else(self: Option, f: fn() -> Option) -> Option

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

fn replace(self: &mut Option, value: T) -> Option

Replaces the value in the option with value, returning the old value if present.

fn take(self: &mut Option) -> Option

Takes the value out of the option, leaving None in its place.

fn transpose(self: Option) -> Result

Transposes into Result<Option<T>, E>; None maps to Ok(None).

fn unwrap(self: Option) -> T

Returns the contained Some value. Panics if the value is None.

fn unwrap_or(self: Option, default: T) -> T

Returns the contained Some value or the provided default.

fn unwrap_or_else(self: Option, f: fn() -> T) -> T

Returns the contained Some value or computes one from f. f is a fn-pointer; non-capturing closures coerce automatically.

fn unzip(self: Option) -> (Option, Option)

Unzips into (Option<A>, Option<B>); None yields (None, None).

fn xor(self: Option, other: Option) -> Option

Returns Some iff exactly one of self and other is Some, otherwise None.

Functions

fndefault

fn default() -> Option

fnis_some_i32

fn is_some_i32(opt: Option) -> bool

Returns true if opt is Some. Compat shim for older call-sites; prefer opt.is_some().

fnoption_flatten

fn option_flatten(opt: Option) -> Option

Flattens Option<Option<T>> into Option<T>.

fnoption_unwrap_or_default

fn option_unwrap_or_default(opt: Option) -> T

Returns the contained Some value or T::default().

fnoption_unzip

fn option_unzip(opt: Option) -> (Option, Option)

Unzips Option<(A, B)> into (Option<A>, Option<B>); None yields (None, None).

fnoption_zip

fn option_zip(a: Option, b: Option) -> Option

Zips two options: returns Some((t, u)) iff both are Some, otherwise None.

fnunwrap_or_i32

fn unwrap_or_i32(opt: Option, def: i32) -> i32

Returns the contained value or def. Compat shim for older call-sites; prefer opt.unwrap_or(def).