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
wrapper writer’s substitution pass. The match.arg codegen path
deliberately splits responsibilities — the proc macro emits placeholders
into the R wrapper, and the wrapper writer resolves them to a concrete c("a", "b", ...) literal (and the check’s aliases = argument, if any) 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 three placeholders (choices_placeholder, aliases_placeholder,
param_doc_placeholder) share the same
{c_ident_without_prefix}_{r_param} stem so the wrapper writer’s 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 three 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.
Constants§
- ALIASES_
PLACEHOLDER_ 🔒PREFIX - Start of every
aliases_placeholder. - CHOICES_
PLACEHOLDER_ 🔒PREFIX - Start of every
choices_placeholder. The shadowing pass (r_shadowing) reads a name with this prefix as a call toc, which is what the placeholder becomes.
Functions§
- aliases_
placeholder 🔒 - R-side placeholder for the trailing
aliases =argument of amatch_argparameter’s check (#1843), written as, <placeholder>after the other arguments. The wrapper writer replaces, <placeholder>with, aliases = base::c("grey" = "gray"), or with nothing when the type has no aliases (registry::match_arg_aliases_arg), from the sameMX_MATCH_ARG_CHOICESentry aschoices_placeholder. The macro can’t tell which:MatchArg::ALIASESresolves at link time, asCHOICESdoes. - c_stem 🔒
- choices_
entry_ 🔒tokens - Emit the
MX_MATCH_ARG_CHOICESstatic + its linkme registration. - choices_
placeholder 🔒 - R-side placeholder that the wrapper writer 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. - param_
key 🔒 - The
{r_param}part of a parameter’s placeholders: its Rust name (rust_name,crate::naming::ident_name) without leading underscores, also when it declares an R formal (#1842). The placeholders are replaced before R reads the text, andplaceholder_ident_suffixmakes Rust identifiers of them, so a declared formal, which may hold a., never becomes part of one. - placeholder_
ident_ 🔒suffix - Derive a safe Rust ident from a write-time placeholder string.