pub trait EnumorphAs: Sized {
// Provided methods
fn widen<T>(self) -> T
where Self: Into<T> { ... }
fn narrow<T>(self) -> Result<T, Self>
where Self: TryInto<T, Error = Self> { ... }
}Expand description
Convenience trait around the conversions provided by Enumorph, but with
the generics on the functions instead of the trait.
use enumorph::{Enumorph, EnumorphAs};
#[derive(Enumorph)]
enum Enum1 {
A(A),
B(B),
}
#[derive(Enumorph)]
enum Enum2 {
A(A),
C(C),
}
struct A;
struct B;
struct C;
let enum_1 = A.widen::<Enum1>();
let enum_2 = A.widen::<Enum2>();Provided Methods§
fn widen<T>(self) -> Twhere
Self: Into<T>,
fn narrow<T>(self) -> Result<T, Self>where
Self: TryInto<T, Error = Self>,
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.