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>
impl<L, R, EL, ER> Converter<L, R> for BoxedFnConverter<L, R, EL, ER>
Source§type ToLeftError<'a> = EL
where
R: 'a
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
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>>
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>>
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.
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>
impl<L, R, EL = Infallible, ER = Infallible> !UnwindSafe for BoxedFnConverter<L, R, EL, ER>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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