Skip to main content

Module match_arg_keys

Module match_arg_keys 

Source
Expand description

Write-time placeholder & symbol-name formatting for the match_arg pipeline.

Tradeoff signpost: this module is the wiring between the #[derive(MatchArg)] proc macro (see match_arg_derive) and the cdylib’s write-time substitution pass. The match.arg codegen path deliberately splits responsibilities — the proc macro emits placeholders into the R wrapper, and the cdylib resolves them to a concrete c("a", "b", ...) literal at write time using MX_MATCH_ARG_CHOICES. That split lets the variant list change without re-running cargo expand on every consumer. Compared to hand-rolling match.arg in a wrapper body, the user gets partial matching, R-visible defaults, and @param doc lines for free, without ever stringifying the variant list in source.

All four shapes (choices_placeholder, param_doc_placeholder, choices_helper_c_name, choices_helper_def_ident) share the same {c_ident_without_prefix}_{r_param} stem so the cdylib’s write-time pass can correlate them. Keep them together so the shape can’t drift.

The c_ident_without_prefix input has C_ already stripped (or is a stem already, e.g. MyType__method). Callers that have a full c_ident should pass c_ident.trim_start_matches("C_").

All four helpers call c_stem(...) internally so callers may also pass a full c_ident (e.g. "C_my_fn") — the C_ prefix is normalized away.

Functions§

c_stem 🔒
choices_entry_tokens 🔒
Emit the MX_MATCH_ARG_CHOICES static + its linkme registration.
choices_helper_c_name 🔒
C symbol name for the helper fn that returns the enum’s choices SEXP, called from the R wrapper’s match.arg prelude.
choices_helper_def_ident 🔒
Rust ident holding the R_CallMethodDef for the match_arg choices helper.
choices_placeholder 🔒
R-side placeholder that the cdylib resolves to a c("a", "b", ...) literal at write time. Substituted by MX_MATCH_ARG_CHOICES entries.
extract_match_arg_default 🔒
Extract the unquoted form of a user-supplied default = "..." literal for a match_arg parameter.
param_doc_entry_tokens 🔒
Emit the MX_MATCH_ARG_PARAM_DOCS static + its linkme registration.
param_doc_placeholder 🔒
R-side placeholder for the @param doc line, substituted by MX_MATCH_ARG_PARAM_DOCS entries at write time. See #210.
placeholder_ident_suffix 🔒
Derive a safe Rust ident from a write-time placeholder string.