Expand description
The ApiKey enum, built as a proc_macro2 token stream via quote!
instead of hand-written write! string templating.
Compare with api_key_enum::emit. The structural payload is identical:
the same variants, discriminants, and doc text. Only the emission
mechanism differs. Things to notice:
- No manual brace or indent bookkeeping. The
quote!block reads like the target code, and repetition is#(#variants)*instead of aforloop thatwriteln!s fragments. syn::parse2validates that the output is real Rust at generation time. A malformed template fails here with a parse error, not three crates downstream when the compiler reads the generated file.emitreturns the raw token string. Therustfmtpass incrate::fmt, which the regeneration binary runs, does the formatting.
One drawback remains. //-style line comments are not tokens, so this
module prepends the // AUTO-GENERATED banner as a string. Doc comments
become #[doc = "…"] attributes, and rustfmt keeps them in that form. It
does not rewrite them to /// without the unstable
normalize_doc_attributes.
Functions§
- emit
- Errors