1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
pub use from::*;
pub use try_from::*;
mod try_from {
/// Fallible type conversion that is analogous to [TryFrom](std::convert::TryFrom).
pub trait TryFromCv<T>
where
Self: Sized,
{
type Error;
fn try_from_cv(from: T) -> Result<Self, Self::Error>;
}
/// Fallible type conversion that is analogous to [TryInto](std::convert::TryInto).
pub trait TryIntoCv<T> {
type Error;
fn try_into_cv(self) -> Result<T, Self::Error>;
}
impl<T, U> TryIntoCv<U> for T
where
U: TryFromCv<T>,
{
type Error = <U as TryFromCv<T>>::Error;
fn try_into_cv(self) -> Result<U, Self::Error> {
U::try_from_cv(self)
}
}
}
mod from {
/// Type conversion that is analogous to [From](std::convert::From).
pub trait FromCv<T> {
fn from_cv(from: T) -> Self;
}
/// Type conversion that is analogous to [Into](std::convert::Into).
pub trait IntoCv<T> {
fn into_cv(self) -> T;
}
impl<T, U> IntoCv<U> for T
where
U: FromCv<T>,
{
fn into_cv(self) -> U {
U::from_cv(self)
}
}
}