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 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 to c, which is what the placeholder becomes.

Functions§

aliases_placeholder 🔒
R-side placeholder for the trailing aliases = argument of a match_arg parameter’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 same MX_MATCH_ARG_CHOICES entry as choices_placeholder. The macro can’t tell which: MatchArg::ALIASES resolves at link time, as CHOICES does.
c_stem 🔒
choices_entry_tokens 🔒
Emit the MX_MATCH_ARG_CHOICES static + its linkme registration.
choices_placeholder 🔒
R-side placeholder that the wrapper writer 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.
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, and placeholder_ident_suffix makes 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.