pub trait EnumerableRef<'a, EnumRef> {
// Required method
fn as_enum_ref(&'a self) -> EnumRef;
}Expand description
A type that can lend itself to the borrowing enum of its sealed trait.
enumerate implements this for every permitted type and makes
for<'a> EnumerableRef<'a, TheSealedTraitRef<'a>> a supertrait. The lifetime is a parameter of
the trait rather than of the method, so the higher-ranked bound is nameable in the supertrait
list, which is what lets a caller reach the enum from a plain &S:
struct Square;
#[enumerate]
#[sealed(Square)]
trait Shape {}
impl Shape for Square {}
let s = □
match s.as_enum_ref() {
AnyShapeRef::Square(s) => { /* .. */ }
}Enumerable cannot do this: into_enum takes self, so reaching the owned enum means owning
the value. The borrowing enum is also the cheaper one to pass, being a pointer and a discriminant
rather than as large as the biggest permitted type.
Required Methods§
Sourcefn as_enum_ref(&'a self) -> EnumRef
fn as_enum_ref(&'a self) -> EnumRef
Wraps &self in the variant of EnumRef that holds this type.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".