Edit Never mind this doesn't work, Don't know why I thought two generics with the same name would be the same type. From and TryFrom can't work unless they are special magic implementations.
I originally wanted to use auto generated From Implementations but there is a problem with that.
let generic : enum(u8, T) = ...;
let concrete : enum(u8, u8) = ...;
let superset : enum (u8, T, &str) = generic | concrete;
// Coercion uses pre-monomorphic types
impl From<enum(u8, T)> for enum(u8, T, &str) {
fn from(source: enum(u8, T)) -> Self {
match source {
enum::0(_0) => _0 as enum::0,
enum::1(_1) => _1 as enum::1, // <-- Second Variant
_ => unreachable!(),
}
}
}
// But if a concrete class is known it will use that From impl
impl From<enum(u8, u8)> for enum(u8, T, &str) {
fn from(source: enum(u8, u8)) -> Self {
match source {
enum::0(_0) => _0 as enum::0,
enum::1(_1) => _1 as enum::0, // <-- First Variant
_ => unreachable!(),
}
}
}
This would require specialization.
From my limited understanding of the specialization RFC. The generic implementation will be used in a generic context, and the concrete implementation will be used in the concrete context (which is what we want) unless the default keyword is used on functions in the generic context. If that is how specialization works then we could implement both From and TryFrom which would be useful for ? and less verbose than as enum.
let generic : enum(u8, T) = concrete.into();
let concrete : enum(u8, u8) = generic.try_into()?;
If someone who knows more about specialization could confirm or deny the above, that would be very helpful.
