Expand description
match.arg-style string conversion for enums.
Provides the MatchArg trait for converting Rust enums to/from R character
strings with partial matching, like R’s match.arg().
Use #[derive(MatchArg)] on C-style enums to auto-generate the implementation.
match.arg-style enum conversion for R string arguments.
This module provides the MatchArg trait for converting between Rust
fieldless enums and R character strings with match.arg semantics
(exact match or unique partial matching).
§Usage
ⓘ
use miniextendr_api::MatchArg;
#[derive(Copy, Clone, MatchArg)]
#[match_arg(rename_all = "snake_case")]
enum Mode {
Fast,
Safe,
Debug,
}
#[miniextendr]
fn run(#[miniextendr(match_arg)] mode: Mode) -> String {
format!("{mode:?}")
}The generated R wrapper uses base::match.arg() for validation before
the main .Call(), giving users familiar R error messages and partial
matching.
Enums§
- Match
ArgError - Error type for
MatchArgconversion failures.
Traits§
- Match
Arg - Trait for enum types that support
match.arg-style string conversion.
Functions§
- choices_
sexp - Build an R character vector (STRSXP) from the choices of a
MatchArgtype. - match_
arg_ from_ sexp - Extract a string from an R SEXP (STRSXP or factor) and match it against
the choices of a
MatchArgtype.