get_enum_discriminant

Function get_enum_discriminant 

Source
fn get_enum_discriminant(
    input: &DeriveInput,
    crate_name: &TokenStream,
) -> Result<(TokenStream, TokenStream)>
Expand description

Get the type of an enum’s discriminant.

For repr(int) and repr(C, int) enums, this will return the known bare integer type specified.

For repr(C) enums, this will extract the underlying size chosen by rustc. It will return a token stream which is a type expression that evaluates to a primitive integer type of this size, using our EnumTagIntegerBytes trait.

For fieldless repr(C) enums, we can feed the size of the enum directly into the trait.

For repr(C) enums with fields, we generate a new fieldless repr(C) enum with the same variants, then use that in the calculation. This is the specified behavior, see https://doc.rust-lang.org/stable/reference/type-layout.html#reprc-enums-with-fields

Returns a tuple of (type ident, auxiliary definitions)