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_CHOICESstatic + 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_CallMethodDeffor the match_arg choices helper. - choices_
placeholder 🔒 - R-side placeholder that the cdylib resolves to a
c("a", "b", ...)literal at write time. Substituted byMX_MATCH_ARG_CHOICESentries. - extract_
match_ 🔒arg_ default - Extract the unquoted form of a user-supplied
default = "..."literal for amatch_argparameter. - param_
doc_ 🔒entry_ tokens - Emit the
MX_MATCH_ARG_PARAM_DOCSstatic + its linkme registration. - param_
doc_ 🔒placeholder - R-side placeholder for the
@paramdoc line, substituted byMX_MATCH_ARG_PARAM_DOCSentries at write time. See #210. - placeholder_
ident_ 🔒suffix - Derive a safe Rust ident from a write-time placeholder string.