Skip to main content

OptionResultBridge

Struct OptionResultBridge 

Source
pub struct OptionResultBridge;
Expand description

Utilities for converting between Option and Result in a typed fashion.

Implementations§

Source§

impl OptionResultBridge

Source

pub fn to_result<T, E>(opt: Option<T>, err: E) -> Result<T, E>

Convert Option<T> to Result<T, E> with a supplied error.

Source

pub fn to_result_with<T, E>( opt: Option<T>, f: impl FnOnce() -> E, ) -> Result<T, E>

Convert Option<T> to Result<T, E> with a lazy error.

Source

pub fn from_result_ok<T, E>(r: Result<T, E>) -> Option<T>

Convert Result<T, E> to Option<T>, discarding the error.

Source

pub fn from_result_err<T, E>(r: Result<T, E>) -> Option<E>

Convert Result<T, E> to Option<E>, discarding the success.

Source

pub fn transpose_result<T, E>(r: Result<Option<T>, E>) -> Option<Result<T, E>>

Transpose Result<Option<T>, E> to Option<Result<T, E>>.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.