pub struct Chars<const CHAR: char, Tail>(pub PhantomData<Tail>);Expand description
The Chars type, a.k.a. ζ, is used to represent type-level list of
Charss, which are equivalent to type-level strings.
Chars is a specialized version of Cons, with the
Head type being fixed to a const-generic value of type Chars.
Similar to Cons, Chars is also parameterized by a Tail type, which is
expected to be either the next Chars, or Nil to
represent the end of the string.
Instead of reusing Cons, we combine the use of Cons within Chars so
that its representation is more compact when shown in compiler error messages.
Similar to Cons, Chars is also shown as ζ to further improve its
readability.
We represent type-level strings as list of Charss, because it is currently
not possible to use types like String or &str as const-generic parameters.
On the other hand, a single Chars can be used as a const-generic parameter,
and so we can workaround the limitation by combining a type-level list of
Charss to represent a type-level string.
Chars is most often not used directly, but rather through the Symbol! macro,
which accepts a string literal and converts it into a list of Charss.
§Example
Given the following symbol definition:
type Hello = Symbol!("hello");The following type would be generated:
type Hello = Chars<'h', Chars<'e', Chars<'l', Chars<'l', Chars<'o', Nil>>>>>;which would be shown with the shortened representation as:
type Hello = ζ<'h', ζ<'e', ζ<'l', ζ<'l', ζ<'o', ε>>>>>;Tuple Fields§
§0: PhantomData<Tail>