Trait OptionUtils

Source
pub trait OptionUtils<T> {
    // Required methods
    fn inner_mut<F>(&mut self, f: F)
       where F: FnOnce(&mut T);
    fn map_into<R>(self) -> Option<R>
       where Self: Sized,
             T: Into<R>;
    fn try_map_into<R, E>(self) -> Result<Option<R>, E>
       where Self: Sized,
             T: TryInto<R, Error = E>;
}
Expand description

A collection of utilities for working with Rust’s Option type.

Required Methods§

Source

fn inner_mut<F>(&mut self, f: F)
where F: FnOnce(&mut T),

Run a function on the inner value of an Option.

Source

fn map_into<R>(self) -> Option<R>
where Self: Sized, T: Into<R>,

Map an Option into another type.

Source

fn try_map_into<R, E>(self) -> Result<Option<R>, E>
where Self: Sized, T: TryInto<R, Error = E>,

Map an Option into another type, returning an error if the conversion fails.

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> OptionUtils<T> for Option<T>

Source§

fn inner_mut<F>(&mut self, f: F)
where F: FnOnce(&mut T),

Source§

fn try_map_into<R, E>(self) -> Result<Option<R>, E>
where Self: Sized, T: TryInto<R, Error = E>,

Source§

fn map_into<R>(self) -> Option<R>
where Self: Sized, T: Into<R>,

Implementors§