Trait FromTag

Source
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:

  • T and Self may 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§

Source

fn from_tag(t: T) -> 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.

Implementations on Foreign Types§

Source§

impl FromTag<(), NoneTag> for ()

Trivial None conversion for unit.

Source§

fn from_tag(_t: ()) -> Self

Source§

impl FromTag<(), SomeTag> for ()

Trivial Some conversion for unit.

Source§

fn from_tag(_t: ()) -> Self

Source§

impl FromTag<[(); 0], ManyTag> for ()

Trivial Many conversion for unit using a zero-sized array.

Source§

fn from_tag(_t: [(); 0]) -> Self

Implementors§

Source§

impl<Type, S> FromTag<(), NoneTag> for SumDynType<Type, S>
where Type: Delimited, S: Get<u32> + Clone + Debug + 'static,

Source§

impl<Type, S> FromTag<Type, SomeTag> for SumDynType<Type, S>
where Type: Delimited, S: Get<u32> + Clone + Debug + 'static,

Source§

impl<Type, const N: usize> FromTag<[Type; N], ManyTag> for SumStaticType<Type, N>
where Type: Delimited,

Source§

impl<Type, const N: usize> FromTag<(), NoneTag> for SumStaticType<Type, N>
where Type: Delimited,

Source§

impl<Type, const N: usize> FromTag<Type, SomeTag> for SumStaticType<Type, N>
where Type: Delimited,