IntoOption

Trait IntoOption 

Source
pub trait IntoOption
where Self: Sized,
{ // Provided methods fn some_if(self, predicate: bool) -> Option<Self> { ... } fn with_some_if<F>(self, predicate: F) -> Option<Self> where F: FnOnce(&Self) -> bool { ... } fn none_if(self, predicate: bool) -> Option<Self> { ... } fn with_none_if<F>(self, predicate: F) -> Option<Self> where F: FnOnce(&Self) -> bool { ... } }
Expand description

Wrap Self in a Option based off a predicate.

Provided Methods§

Source

fn some_if(self, predicate: bool) -> Option<Self>

Results Some(self) if the predicate returns true, or None otherwise.

Source

fn with_some_if<F>(self, predicate: F) -> Option<Self>
where F: FnOnce(&Self) -> bool,

Results Some(self) if the predicate returns true, or None otherwise.

Source

fn none_if(self, predicate: bool) -> Option<Self>

Results None if the predicate returns true, or Some(self) otherwise.

Source

fn with_none_if<F>(self, predicate: F) -> Option<Self>
where F: FnOnce(&Self) -> bool,

Results None if the predicate returns true, or Some(self) otherwise.

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.

Implementors§

Source§

impl<T> IntoOption for T