Trait FallibleMapExt

Source
pub trait FallibleMapExt<T, U, E> {
    // Required method
    fn try_map<F>(self, f: F) -> Result<Option<U>, E>
       where F: FnOnce(T) -> Result<U, E>;
}
Expand description

Extend Option with a fallible map method

This is useful for mapping fallible operations (i.e. operations that) return Result, over an optional type. The result will be Result<Option<U>>, which makes it easy to handle the errors that originate from inside the closure that’s being mapped.

§Type parameters

  • T: The input Option’s value type
  • U: The outputs Option’s value type
  • E: The possible error during the mapping

Required Methods§

Source

fn try_map<F>(self, f: F) -> Result<Option<U>, E>
where F: FnOnce(T) -> Result<U, E>,

Try to apply a fallible map function to the option

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T, U, E> FallibleMapExt<T, U, E> for Option<T>

Source§

fn try_map<F>(self, f: F) -> Result<Option<U>, E>
where F: FnOnce(T) -> Result<U, E>,

Implementors§