Skip to main content

variant_constructor_at

Function variant_constructor_at 

Source
pub fn variant_constructor_at(
    path: &[SmolStr],
    arg_types: &[DataType],
    span: Span,
    ctx: Ctx,
    state: &mut State<'_>,
) -> Option<(u16, u16)>
Expand description

Resolves a variant constructor to the enum it names and the index of the variant, instantiating a generic enum at the types its payload names.

A plain enum resolves by name, the way it always has. A generic enum has no registered type until something names one, so the constructor makes it: the arguments bind the parameters the variant declares, and a parameter the payload does not mention stands for any. Ok(2) is therefore a Result<int, any> and None on its own an Option<any>, and param_type_matches is what lets those go where a fully named instantiation is expected.

Returns None when no generic enum declares a variant of that name, which is what leaves plain enums and ordinary calls to the paths that follow. The enum and variant a constructor names, at the types its payload is given: a generic enum instantiated at what the payload binds, or a plain enum resolved by name.