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, BoxedFnConverter};
use std::convert::Infallible;
use std::num::TryFromIntError;
let converter = boxed_fn_converter(
// Right to left
|i: &i32| -> Result<u8, TryFromIntError> { (*i - 100).try_into() },
// Left to right
|u: &u8| -> Result<i32, Infallible> { Ok((*u as i32) + 100) },
);
// The type of the converter is descriptable! This is not the case with [`fn_converter()`].
let pair: Pair<u8, i32, BoxedFnConverter<u8, i32, TryFromIntError, Infallible>> =
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 = EL
type ToLeftError = EL
The error type returned when converting from right to left.
Source§type ToRightError = ER
type ToRightError = ER
The error type returned when converting from left to right.
Source§fn convert_to_left(&self, right: &R) -> Result<L, Self::ToLeftError>
fn convert_to_left(&self, right: &R) -> Result<L, Self::ToLeftError>
Converts a reference to a right value into a left value.
Source§fn convert_to_right(&self, left: &L) -> Result<R, Self::ToRightError>
fn convert_to_right(&self, left: &L) -> Result<R, Self::ToRightError>
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