generate_tag_consts

Function generate_tag_consts 

Source
fn generate_tag_consts(data: &DataEnum) -> TokenStream
Expand description

Generates a constant for the tag associated with each variant of the enum. When we match on the enum’s tag, each arm matches one of these constants. We have to use constants here because:

  • The type that we’re matching on is not the type of the tag, it’s an integer of the same size as the tag type and with the same bit patterns.
  • We can’t read the enum tag as an enum because the bytes may not represent a valid variant.
  • Patterns do not currently support const expressions, so we have to assign these constants to names rather than use them inline in the match statement.