use core::convert::Infallible;
pub trait ConvertFrom<F>: Sized {
fn convert_from(value: F) -> Self;
}
pub trait ConvertInto<T>: Sized {
fn convert_into(self) -> T;
}
pub trait ConvertTryFrom<F>: Sized {
type Error;
fn convert_try_from(value: F) -> Result<Self, Self::Error>;
}
pub trait ConvertTryInto<T>: Sized {
type Error;
fn convert_try_into(self) -> Result<T, Self::Error>;
}
impl<F: ConvertInto<T>, T> ConvertTryFrom<F> for T {
type Error = Infallible;
fn convert_try_from(value: F) -> Result<T, Infallible> {
Ok(value.convert_into())
}
}
impl<F, T: ConvertFrom<F>> ConvertInto<T> for F {
fn convert_into(self) -> T {
T::convert_from(self)
}
}
impl<F, T: ConvertTryFrom<F>> ConvertTryInto<T> for F {
type Error = T::Error;
fn convert_try_into(self) -> Result<T, T::Error> {
T::convert_try_from(self)
}
}