Skip to main content

build_match_arg_prelude

Function build_match_arg_prelude 

Source
pub(crate) fn build_match_arg_prelude(
    per_param: &HashMap<String, ParamAttrs>,
) -> Vec<String>
Expand description

Build R prelude lines that validate match_arg / choices / several_ok parameters via base::match.arg() before the .Call().

Returns an empty vector when the method declares none. Both match_arg and choices(...) carry their choice list as the formal default (c("a", "b", ...)), so base::match.arg(arg) finds the list by itself — no second arg, no C helper lookup. match_arg adds a factor → character coercion in front of match.arg.

Shared by MethodContext::match_arg_prelude (inherent impls) and TraitMethodContext::match_arg_prelude (trait impls) — see audit/2026-07-03-dogfooding-macros-codegen.md finding #1 (trait methods previously had no match_arg support at all).