pub trait Converter<L, R> {
type ToLeftError<'a>
where R: 'a;
type ToRightError<'a>
where L: 'a;
// Required methods
fn convert_to_left<'a>(
&self,
right: &'a R,
) -> Result<L, Self::ToLeftError<'a>>;
fn convert_to_right<'a>(
&self,
left: &'a L,
) -> Result<R, Self::ToRightError<'a>>;
}Expand description
A trait for converting between two types.
This trait is used by Pair to convert between its left and right values.
§Example
use cached_pair::Converter;
use std::convert::Infallible;
use std::num::ParseIntError;
struct MyConverter;
impl Converter<i32, String> for MyConverter {
type ToLeftError<'a> = ParseIntError;
type ToRightError<'a> = Infallible;
fn convert_to_left(&self, right: &String) -> Result<i32, Self::ToLeftError<'_>> {
right.parse()
}
fn convert_to_right(&self, left: &i32) -> Result<String, Self::ToRightError<'_>> {
Ok(left.to_string())
}
}Required Associated Types§
Sourcetype ToLeftError<'a>
where
R: 'a
type ToLeftError<'a> where R: 'a
The error type returned when converting from right to left.
Sourcetype ToRightError<'a>
where
L: 'a
type ToRightError<'a> where L: 'a
The error type returned when converting from left to right.
Required Methods§
Sourcefn 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.
Sourcefn 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.
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.