use core::convert::Infallible; /// Adds infallible conversions between crates that mirrors [`From`]. pub trait ConvertFrom: Sized { /// Infallibly converts a value of type `F` to a value of type `Self`. fn convert_from(value: F) -> Self; } /// Adds infallible conversions between crates that mirrors [`Into`]. pub trait ConvertInto: Sized { /// Infallibly converts a value of type `Self` to a value of type `T`. fn convert_into(self) -> T; } /// Adds fallible conversions between crates that mirrors [`TryFrom`]. pub trait ConvertTryFrom: Sized { /// The type of an error that can occur during a conversion. /// /// In this crate, all errors correspond to the [`Error`](crate::Error) /// type. type Error; /// Fallibly converts a value of type `F` to a value of type `Self`. fn convert_try_from(value: F) -> Result; } /// Adds fallible conversions between crates that mirrors [`TryInto`]. pub trait ConvertTryInto: Sized { /// The type of an error that can occur during a conversion. /// /// In this crate, all errors correspond to the [`Error`](crate::Error) /// type. type Error; /// Fallibly converts a value of type `Self` to a value of type `T`. fn convert_try_into(self) -> Result; } impl, T> ConvertTryFrom for T { type Error = Infallible; fn convert_try_from(value: F) -> Result { Ok(value.convert_into()) } } impl> ConvertInto for F { fn convert_into(self) -> T { T::convert_from(self) } } impl> ConvertTryInto for F { type Error = T::Error; fn convert_try_into(self) -> Result { T::convert_try_from(self) } }