pub const fn assert_tag_not_a_field<P: Keys, E>(tag: &str, _ctor: fn(P) -> E)Expand description
Refuse an internally tagged declaration whose tag is also a field of the variant’s payload.
The two share one object, so a collision writes the name twice:
{"kind":"Config","kind":"debug"}. This crate reads that back, taking the
first member as the tag, and a last-wins parser does not: it resolves the
name to the payload’s value and the variant is gone. The field is
unreadable here as well, the tag having been consumed before the payload’s
members are reached, so the configuration is dead in both directions rather
than merely unwise.
ctor is never called. A tuple variant’s constructor is a value of type
fn(P) -> E, so naming it is what tells this function what P is: the
payload’s type is deliberately absent from the declaration, and the
constructor is the one place the macro can reach it without asking for it
twice. tag is an ordinary argument rather than an associated constant
because the call sites are const contexts holding the literal, which is
what keeps this free of any trait the enum would have to implement.
tagged_enum! calls it, for a declaration carrying a
tag clause, from an item-level const, so with no generics it is evaluated
by cargo check. A generic one has no keys until it is instantiated, and
is checked from the write path’s own const block instead, which is
Keys::REQUIRED’s tier: reported when the crate is built.
Comparing bytes rather than ==, str equality not being callable in a
const context on this crate’s minimum compiler.