Trait DiscriminantTag

Source
pub trait DiscriminantTag { }
Expand description

Marker trait for type-level discriminants.

A Discriminant is a zero-sized type used to uniquely identify behavior, structure, or interpretation at the type level.

§Guidelines

Implementors should:

  • be zero-sized types (ZST)
  • carry no runtime data
  • act purely as type-level identifiers

§Motivation

In Rust, trait implementations involving generic or associated types can become ambiguous under the coherence rules:

  • generic parameters may unify in unexpected ways
  • multiple impls may overlap when types are not fully concrete
  • the compiler must conservatively reject such cases

To avoid this, a concrete type-level key is introduced as a discriminant.

By adding a Discriminant:

  • each implementation becomes uniquely identifiable
  • ambiguity between generic impls is disposed
  • coherence is preserved without restricting expressiveness

§Role in the System

Discriminants are used in some cases like

They allow multiple interpretations over the same underlying types without conflict.

Implementations on Foreign Types§

Source§

impl DiscriminantTag for ()

Default Discriminant implementation if no multiple interpretations are required.

Implementors§