Skip to main content

Module r_wrapper_builder

Module r_wrapper_builder 

Source
Expand description

Shared utilities for building R wrapper code.

This module provides builders for constructing R function signatures and call arguments consistently across both standalone functions and impl methods.

§Key Components

§Usage

ⓘ
// Build R function signature
let formals = build_r_formals_from_sig(&method.sig, &r_formals, &defaults);
let call_args = build_r_call_args_from_sig(&method.sig, &r_formals, absent_formals);

// Build .Call() invocation
let call = DotCallBuilder::new("C_MyType__method")
    .with_self("self")
    .with_args(&["x", "y"])
    .build();

// Build roxygen tags
let tags = RoxygenBuilder::new("MyType")
    .name("method")
    .rdname("MyType")
    .export()
    .build();

Structs§

DotCallBuilder
Builder for formatting .Call() invocations in R wrapper code.
Formals 🔒
The R formal of each parameter of one signature (#1842).
RArgumentBuilder
Builder for R function formal parameters and call arguments.
RngSeedContract 🔒
The seed contract of stats::simulate(), which #[miniextendr(rng(seed = <param>))] writes into a standalone wrapper in the order stats:::simulate.lm uses (#2198).
RoxygenBuilder
Builder for generating roxygen2 documentation tags.

Enums§

CallAttribution
Which frame a generated wrapper hands to .Call(.., .call = ..) and uses as the raise fallback (.miniextendr_raise_condition(.val, <default>)).

Constants§

FRAMEWORK_FORMALS 🔒
The R names a declared formal must not take, beyond R’s own syntax rules: the names the generated wrapper binds or reads in the function’s frame (#1842). Another dotted name is the framework’s only when it starts with one of FRAMEWORK_FORMAL_PREFIXES.
FRAMEWORK_FORMAL_PREFIXES 🔒
Prefixes of the R names the framework generates (locals such as .mx_call and .mx_self, the wrappers preamble’s .miniextendr_* helpers, the .rdata_* helpers #[derive(ExternalPtr)] writes for a sidecar, the write-time .__MX_* placeholders): a declared formal starting with one is refused.

Functions§

build_r_call_args_from_sig 🔒
Build R .Call() arguments from a Rust function signature.
build_r_formals_from_sig 🔒
Build R formal parameters from a Rust function signature, with optional defaults.
check_r_formals 🔒
Check the R formals a signature produces, before any wrapper is generated.
declared_formal_problem 🔒
Why formal can’t be a declared formal, or None when it can: it must be a syntactic R name (crate::naming::is_syntactic_r_name: letters, digits, . and _, not starting with a digit, _ or . and a digit, and not a reserved word), not ... or ..1 (R’s dots), and none of the names the generated wrapper binds itself (FRAMEWORK_FORMALS, FRAMEWORK_FORMAL_PREFIXES).
is_missing_type 🔒
Check if a type is Missing<T> by examining the last path segment.
normalize_r_arg_string
Normalizes a Rust argument name (its crate::naming::ident_name, no r#) for R.
r_formal_names 🔒
The R formal each parameter of a signature becomes, with the parameter’s ident: Formals::of its name. The &Dots / LazyDots parameter becomes ... wherever it sits and is skipped, as are receivers, non-ident patterns and an NArgs parameter, which is no formal (#1860).
split_choice_list 🔒
Split a comma-separated choices list (as given to choices(param = "a, b, c")) into individual trimmed entries. Surrounding double-quotes are tolerated so users can spell the list either way: "a, b" or "\"a\", \"b\"".
with_call_formal 🔒
Append a standalone wrapper’s CallAttribution::formal to its joined formals (#1613). The formal goes last: after ... and after any formal that follows the dots, so positional extras land in the dots and .call is matched by name only; a wrapper without other formals takes it alone.