What does enum variant in braces in a return type declaration mean?

What does ast::Ast {ast::Ast::Addition} etc. mean in the following error message? Ast is an enum and Addition and Subtraction are its variants.

note: expected type `peg_runtime::RuleResult<(fn(std::boxed::Box<_>, std::boxed::Box<_>) -> ast::Ast {ast::Ast::Addition}, ast::Ast)>`
         found enum `peg_runtime::RuleResult<(fn(std::boxed::Box<_>, std::boxed::Box<_>) -> ast::Ast {ast::Ast::Subtraction}, ast::Ast)>`

Can I declare my own variables and return types with this style of type declaration?

Can you post the code that causes the error along with the full error message?

That's a function item, fn(args...) -> ret {function name}. You probably need to cast ast::Ast::Addition as fn(_, _) -> _. This is because the type of a function is a unique type that only refers to that function. But that unique type can be coerced to a function pointer. We can probably help you better if you gave more context.

1 Like

To add to that: Tuple-variant constructors are simply functions that take the elements of the tuple as arguments and produce a value of the enum type.