pub(crate) struct MiniextendrFnAttrs {Show 32 fields
pub(crate) force_worker: bool,
pub(crate) force_invisible: Option<bool>,
pub(crate) check_interrupt: bool,
pub(crate) coerce_all: bool,
pub(crate) rng: bool,
pub(crate) rng_seed: Option<Ident>,
pub(crate) unwrap_in_r: bool,
pub(crate) serialize: bool,
pub(crate) wrap: Option<ClassSystem>,
pub(crate) serde_error: Option<SerdeErrorSpec>,
pub(crate) preconditions: Option<bool>,
pub(crate) call_attribution: Option<CallAttribution>,
pub(crate) call_arg: bool,
pub(crate) return_pref: ReturnPref,
pub(crate) return_pref_span: Option<Span>,
pub(crate) s3_generic: Option<String>,
pub(crate) s3_class: Option<String>,
pub(crate) dots_spec: Option<TokenStream>,
pub(crate) dots_policy: Option<DotsPolicy>,
pub(crate) dots_span: Option<Span>,
pub(crate) lifecycle: Option<LifecycleSpec>,
pub(crate) strict: bool,
pub(crate) internal: bool,
pub(crate) noexport: bool,
pub(crate) export: bool,
pub(crate) doc: Option<String>,
pub(crate) c_symbol: Option<String>,
pub(crate) r_name: Option<String>,
pub(crate) postfix: Option<String>,
pub(crate) r_entry: Option<String>,
pub(crate) r_post_checks: Option<String>,
pub(crate) r_on_exit: Option<ROnExit>,
}Expand description
Parsed arguments for the #[miniextendr(...)] attribute on functions.
This is intentionally a small, “data-only” struct that:
- Owns the parsing rules for the attribute
- Produces a normalized, easy-to-consume representation for codegen
§Accepted flags
invisible/visible: control whether the generated R wrapper returns invisiblycheck_interrupt: insertR_CheckUserInterrupt()before calling Rustworker: opt into worker-thread execution (default is main thread)coerce: enable automatic coercion for supported parameter typesrng: enable RNG state management (GetRNGstate/PutRNGstate)rng(seed = <param>):rng, plus the seed contract ofstats::simulate()in the R wrapper (#2198);<param>names the parameter, by its Rust name, whose value goes toset.seed()unwrap_in_r: returnResult<T, E>to R without unwrappingprefer = "auto" | "list" | "externalptr" | "vector": prefer a specificIntoRpathno_preconditions/preconditions(bare or= true/false): drop or keep the R-side type checks. Without themTryFromSexpstill raises on bad input, with the same argument-error condition (#1591); the message comes from the conversion. Saves oneisTRUE()guard per check. Hot-path opt-in. The last one written wins. A parameter decides for itself first (Checked<T>/Unchecked<T>, or the per-parameter#[miniextendr(preconditions)]/#[miniextendr(no_preconditions)]); below the function come the crate’s[package.metadata.miniextendr] preconditions = true | falseand then theno-preconditions-defaultfeature (crate::r_preconditions::resolve_type_checks).call = wrapper | caller | none: which call the wrapper attributes conditions to (#1566), always as written.wrapper(the framework default) passes.call = sys.call();callerbinds the caller’s call first and passes that (internal entry points behind a hand-written R function; needsnoexport/internal);nonepasses no call, so every condition, the argument errors included, has a NULL call (#1851; not with aCall/CallerCallparameter orcall_arg). ACall/CallerCallparameter is the marker spelling ofwrapper/caller, and[package.metadata.miniextendr] call_attributionthe crate default; seeCallAttribution::resolve. On an S3 methodwrapperreports the generic’s call (CallAttribution::for_s3_method).call_arg: the wrapper takes a trailing.call = NULLformal (#1834), exported or not.NULLis the wrapper’s own call; an R function composing the function passes.call = environment()(or a call object) and its conditions name that function’s call instead. Not withcall = caller(whose wrapper already takes.call) ors3(...).
§Note
Unknown flags are rejected with a compile error to avoid silently ignoring typos.
Fields§
§force_worker: boolForce execution on worker thread (set by worker).
force_invisible: Option<bool>Override visibility; Some(true) makes the wrapper return invisibly, Some(false) forces visibility.
check_interrupt: boolInsert R_CheckUserInterrupt() before calling the Rust function.
coerce_all: boolEnable automatic coercion for all parameters that support it.
rng: boolEnable RNG state management (GetRNGstate/PutRNGstate). Also set by
rng(seed = ..).
rng_seed: Option<Ident>rng(seed = <param>) (#2198): the parameter, by its Rust name, whose
value the R wrapper passes to set.seed() before the call and records
in the result’s seed attribute, as stats:::simulate.lm does
(check_rng_seed checks it against the signature).
unwrap_in_r: boolReturn Result<T, E> to R without unwrapping.
serialize: boolSerialize the complete return value through AsSerialize<T>.
wrap: Option<ClassSystem>§serde_error: Option<SerdeErrorSpec>Build the Err arm’s condition from the error’s serde output
(#[miniextendr(serde_error(shape = .., tag = .., prefix = .., ..))]).
preconditions: Option<bool>Keep (Some(true)) or drop (Some(false)) the R-side type-check
guards of the parameters that do not decide for themselves.
TryFromSexp already raises the same argument-error condition on
mismatched input (#1591), so the information isn’t lost: it is
worded by the conversion rather than by the R check. Useful for hot
paths where the per-call precondition cost (one isTRUE() guard per
check) dominates over actual work.
Some(true) from #[miniextendr(preconditions)] (or
preconditions = true, no_preconditions = false), Some(false) from
no_preconditions (or no_preconditions = true, preconditions = false); the last one written wins. None: the crate default, then the
no-preconditions-default feature decide, at codegen
(crate::r_preconditions::resolve_type_checks).
call_attribution: Option<CallAttribution>The attribution the attribute asked for, if any (#1566):
call = wrapper | caller | none. None here means the attribute said
nothing; the codegen then falls back to a Call / CallerCall
parameter marker, the crate default and finally wrapper
(crate::r_wrapper_builder::CallAttribution::resolve).
call_arg: boolcall_arg (#1834): the wrapper takes a trailing .call = NULL formal,
whose NULL is the wrapper’s own call and through which an R function
composing it passes another (environment(), a call object). Turns
wrapper attribution into
crate::r_wrapper_builder::CallAttribution::Argument.
return_pref: ReturnPrefPreferred return conversion: forces AsList/AsExternalPtr/AsRNative wrapping
of the return value before IntoR::into_sexp is called.
return_pref_span: Option<Span>Span of the prefer = ... attribute, for error reporting when the return type
falls into a codegen category (Option<T>, Result<T, E>, (), Self, raw
SEXP, …) that can’t honor it.
s3_generic: Option<String>S3 generic name (if this function is an S3 method).
Use #[miniextendr(s3(generic = "vec_proxy", class = "my_vctr"))] to mark a function
as an S3 method for an existing generic. pkg::generic registers the
method lazily, for a generic of a suggested package (#2154).
s3_class: Option<String>S3 class suffix for the method (e.g., “my_vctr” or “my_vctr.my_vctr” for double-dispatch).
dots_spec: Option<TokenStream>Typed list validation spec for dots parameter.
Use #[miniextendr(dots = typed_list!(...))] to automatically validate dots
at the start of the function and bind the result to dots_typed.
dots_policy: Option<DotsPolicy>What the function’s ... takes: dots = empty | empty(allow = [..]) | forward(allow = [..]) | data (#2157, crate::dots_policy).
dots_span: Option<Span>Span of the dots = ... attribute for error reporting.
lifecycle: Option<LifecycleSpec>Lifecycle specification for deprecation/experimental status.
strict: boolStrict output conversion: panic instead of lossy widening for i64/u64/isize/usize.
internal: boolMark as internal: adds @keywords internal, suppresses @export.
noexport: boolSuppress @export without adding @keywords internal.
export: boolForce @export even on non-pub functions. Antidote to noexport.
doc: Option<String>Custom roxygen documentation override.
When set, replaces auto-extracted roxygen from Rust doc comments.
Each \n in the string becomes a separate #' line.
c_symbol: Option<String>Custom C symbol name for the generated wrapper.
Overrides the default C_<crate>_<fn_name> naming convention. The value is used
verbatim (no crate prefix) — the author owns cross-package uniqueness on webR (#1273).
Must be a valid C identifier (alphanumeric + underscore, starting with letter or underscore).
r_name: Option<String>Override R wrapper function name.
Use #[miniextendr(r_name = "is.my_type")] to give the R wrapper a different name
than the Rust function. The C symbol is still derived from the Rust name.
Cannot be combined with s3(generic/class) — use generic/class for S3 naming.
postfix: Option<String>Append a fixed suffix to the Rust name for the R wrapper
(#[miniextendr(noexport, postfix = "_impl")] on fn f yields f_impl).
States the “hand-written f() delegates to generated f_impl()”
convention without repeating the name in r_name. Exclusive with
r_name and s3(...); the C symbol is unchanged.
r_entry: Option<String>R code to inject at the very top of the wrapper body (before all built-in checks).
Use #[miniextendr(r_entry = "x <- as.integer(x)")] to run R code before
missing-default handling, lifecycle checks, preconditions, and match.arg.
Multi-line via \n. No validation of R syntax.
r_post_checks: Option<String>R code to inject after all built-in checks, immediately before .Call().
Use #[miniextendr(r_post_checks = "message('calling rust')")] to run R code
after all precondition checks but before the Rust function is invoked.
Multi-line via \n. No validation of R syntax.
r_on_exit: Option<ROnExit>Register on.exit() cleanup code in the R wrapper.
Short form: #[miniextendr(r_on_exit = "close(con)")] → on.exit(close(con), add = TRUE)
Long form: #[miniextendr(r_on_exit(expr = "close(con)", add = false))]
Defaults: add = TRUE, after = TRUE. Injected after r_entry, before other checks.
Trait Implementations§
Source§impl Default for MiniextendrFnAttrs
impl Default for MiniextendrFnAttrs
Source§impl Parse for MiniextendrFnAttrs
Parses the comma-separated option list inside #[miniextendr(...)].
impl Parse for MiniextendrFnAttrs
Parses the comma-separated option list inside #[miniextendr(...)].
Supports three syntactic forms for each option:
- Bare identifier:
#[miniextendr(invisible)] - Name-value:
#[miniextendr(prefer = "list")]or#[miniextendr(invisible = true)] - Nested list:
#[miniextendr(s3(generic = "...", class = "..."))]
Options with negated forms (no_worker, no_coerce, no_strict) explicitly
disable the corresponding flag, which is useful for overriding feature-based
defaults.
An empty input (plain #[miniextendr]) resolves all options to their feature-based
defaults (e.g., worker-default, coerce-default, strict-default).
§Errors
Returns a compile error for:
- Unknown option names (prevents silent typos)
- Mutually exclusive options (
internal+noexport) - Invalid values for key-value options (e.g., bad
preferorc_symbol) - Missing required sub-options (e.g.,
s3(...)withoutclass)
fn parse(input: ParseStream<'_>) -> Result<Self>
Auto Trait Implementations§
impl !Send for MiniextendrFnAttrs
impl !Sync for MiniextendrFnAttrs
impl Freeze for MiniextendrFnAttrs
impl RefUnwindSafe for MiniextendrFnAttrs
impl Unpin for MiniextendrFnAttrs
impl UnsafeUnpin for MiniextendrFnAttrs
impl UnwindSafe for MiniextendrFnAttrs
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> SizeHint for Twhere
T: ?Sized,
impl<T> SizeHint for Twhere
T: ?Sized,
Source§default fn lower_bound(&self) -> usize
default fn lower_bound(&self) -> usize
core_io_internals)[u8; 12] could return any value between 0 and
12 inclusively as a correct implementation. Read moreSource§impl<T> SizedTypeProperties for T
impl<T> SizedTypeProperties for T
Source§#[doc(hidden)]const SIZE: usize = _
#[doc(hidden)]const SIZE: usize = _
sized_type_properties)Source§#[doc(hidden)]const ALIGN: usize = _
#[doc(hidden)]const ALIGN: usize = _
sized_type_properties)Source§#[doc(hidden)]const ALIGNMENT: Alignment = _
#[doc(hidden)]const ALIGNMENT: Alignment = _
ptr_alignment_type)Source§#[doc(hidden)]const IS_ZST: bool = _
#[doc(hidden)]const IS_ZST: bool = _
sized_type_properties)Source§#[doc(hidden)]const LAYOUT: Layout = _
#[doc(hidden)]const LAYOUT: Layout = _
sized_type_properties)Source§#[doc(hidden)]const MAX_SLICE_LEN: usize = _
#[doc(hidden)]const MAX_SLICE_LEN: usize = _
sized_type_properties)[Self]. Read moreLayout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 720 bytes