Struct BoxedFnConverter

Source
pub struct BoxedFnConverter<L, R, EL = Infallible, ER = Infallible> { /* private fields */ }
Expand description

A converter that uses boxed closures for conversions. This is similar to FnConverter but uses trait objects, making its type always descriptable.

§Example

use cached_pair::{Pair, boxed_fn_converter};
use std::convert::Infallible;
use std::num::TryFromIntError;

let converter = boxed_fn_converter(
    |i: &i32| -> Result<u8, TryFromIntError> { (*i - 100).try_into() },
    |u: &u8| -> Result<i32, Infallible> { Ok((*u as i32) + 100) },
);

let pair = Pair::from_right_conv(142i32, converter);
assert_eq!(pair.try_left(), Ok(&42u8));

Trait Implementations§

Source§

impl<L, R, EL, ER> Converter<L, R> for BoxedFnConverter<L, R, EL, ER>

Source§

type ToLeftError<'a> = EL where R: 'a

The error type returned when converting from right to left.
Source§

type ToRightError<'a> = ER where L: 'a

The error type returned when converting from left to right.
Source§

fn convert_to_left<'a>(&self, right: &'a R) -> Result<L, Self::ToLeftError<'a>>

Converts a reference to a right value into a left value.
Source§

fn convert_to_right<'a>(&self, left: &'a L) -> Result<R, Self::ToRightError<'a>>

Converts a reference to a left value into a right value.
Source§

impl<L, R, EL, ER> Debug for BoxedFnConverter<L, R, EL, ER>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<L, R, EL, ER> Freeze for BoxedFnConverter<L, R, EL, ER>

§

impl<L, R, EL = Infallible, ER = Infallible> !RefUnwindSafe for BoxedFnConverter<L, R, EL, ER>

§

impl<L, R, EL = Infallible, ER = Infallible> !Send for BoxedFnConverter<L, R, EL, ER>

§

impl<L, R, EL = Infallible, ER = Infallible> !Sync for BoxedFnConverter<L, R, EL, ER>

§

impl<L, R, EL, ER> Unpin for BoxedFnConverter<L, R, EL, ER>
where L: Unpin, R: Unpin,

§

impl<L, R, EL = Infallible, ER = Infallible> !UnwindSafe for BoxedFnConverter<L, R, EL, ER>

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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.