pub trait FromTag<T, Discriminant: DiscriminantTag = ()>: Sized {
// Required method
fn from_tag(t: T) -> Self;
}Expand description
Converts a value T into Self under a given discriminant.
Unlike From, this trait introduces an additional type parameter
(Discriminant implementing DiscriminantTag via
discriminants or impl_discriminants)
to distinguish between conversions that would otherwise overlap under
Rust’s coherence rules.
This is necessary because:
TandSelfmay be generic or associated types (i.e., not fully concrete)- such types may unify in the future
- the compiler must conservatively reject potentially overlapping impls
By adding a concrete discriminant (tag), each conversion becomes uniquely identifiable at the type level.
§Type Parameters
T: Source type (may be generic or non-concrete).Discriminant: A concrete marker type used to disambiguate conversions.
§Default Discriminant
Discriminant = (): uses the unit type as a default tag, meaning no additional disambiguation when a single interpretation exists.
Required Methods§
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.
Implementations on Foreign Types§
Source§impl FromTag<[(); 0], ManyTag> for ()
Trivial Many conversion for unit using a zero-sized array.
impl FromTag<[(); 0], ManyTag> for ()
Trivial Many conversion for unit using a zero-sized array.