Skip to main content

derive_match_arg

Function derive_match_arg 

Source
pub fn derive_match_arg(input: DeriveInput) -> Result<TokenStream>
Expand description

Main entry point for #[derive(MatchArg)].

Generates three trait implementations:

  • impl MatchArg – provides CHOICES (static string slice), from_choice, to_choice
  • impl TryFromSexp – converts R character scalar to enum variant via match_arg_from_sexp
  • impl IntoR – converts enum variant to R character scalar via to_choice().into_sexp()

impl IntoR for Vec<Self> is provided automatically by the blanket impl<T: MatchArg> IntoR for Vec<T> in miniextendr-api::match_arg, so returning Vec<EnumName> from a #[miniextendr] function works without any extra code in the user’s crate.

Validates:

  • Only enums are accepted (not structs or unions)
  • Generic enums are rejected
  • At least one variant is required
  • Only fieldless (C-style) variants are allowed
  • No duplicate choice names after renaming

Choice names default to variant identifiers, optionally transformed by #[match_arg(rename_all = "...")] or overridden per-variant with #[match_arg(rename = "...")].