Skip to main content

FoldWithOption

Trait FoldWithOption 

Source
pub trait FoldWithOption: Sized {
    // Provided methods
    fn fold_with<U>(
        self,
        opt: Option<U>,
        f: impl FnOnce(Self, U) -> Self,
    ) -> Self { ... }
    fn try_fold_with<U, E>(
        self,
        opt: Option<U>,
        f: impl FnOnce(Self, U) -> Result<Self, E>,
    ) -> Result<Self, E> { ... }
}
Available on crate feature internal-api only.
Expand description

Extension trait for folding zero or one value from an Option into a base value.

Provided Methods§

Source

fn fold_with<U>(self, opt: Option<U>, f: impl FnOnce(Self, U) -> Self) -> Self

Applies an optional fold operation f to self if opt is Some; otherwise returns self unchanged.

Similar to opt.iter().fold(self, |acc, value| f(acc, value)), but accepting FnOnce instead of requiring FnMut, and with the base value as receiver instead of the option.

Source

fn try_fold_with<U, E>( self, opt: Option<U>, f: impl FnOnce(Self, U) -> Result<Self, E>, ) -> Result<Self, E>

Fallible fold_with: applies Result-returning f to self if opt is Some, otherwise returns self unchanged (wrapped in Ok).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§