Skip to main content

MiniextendrFnAttrs

Struct MiniextendrFnAttrs 

Source
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 invisibly
  • check_interrupt: insert R_CheckUserInterrupt() before calling Rust
  • worker: opt into worker-thread execution (default is main thread)
  • coerce: enable automatic coercion for supported parameter types
  • rng: enable RNG state management (GetRNGstate/PutRNGstate)
  • rng(seed = <param>): rng, plus the seed contract of stats::simulate() in the R wrapper (#2198); <param> names the parameter, by its Rust name, whose value goes to set.seed()
  • unwrap_in_r: return Result<T, E> to R without unwrapping
  • prefer = "auto" | "list" | "externalptr" | "vector": prefer a specific IntoR path
  • no_preconditions / preconditions (bare or = true/false): drop or keep the R-side type checks. Without them TryFromSexp still raises on bad input, with the same argument-error condition (#1591); the message comes from the conversion. Saves one isTRUE() 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 | false and then the no-preconditions-default feature (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(); caller binds the caller’s call first and passes that (internal entry points behind a hand-written R function; needs noexport / internal); none passes no call, so every condition, the argument errors included, has a NULL call (#1851; not with a Call / CallerCall parameter or call_arg). A Call / CallerCall parameter is the marker spelling of wrapper / caller, and [package.metadata.miniextendr] call_attribution the crate default; see CallAttribution::resolve. On an S3 method wrapper reports the generic’s call (CallAttribution::for_s3_method).
  • call_arg: the wrapper takes a trailing .call = NULL formal (#1834), exported or not. NULL is 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 with call = caller (whose wrapper already takes .call) or s3(...).

§Note

Unknown flags are rejected with a compile error to avoid silently ignoring typos.

Fields§

§force_worker: bool

Force 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: bool

Insert R_CheckUserInterrupt() before calling the Rust function.

§coerce_all: bool

Enable automatic coercion for all parameters that support it.

§rng: bool

Enable 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: bool

Return Result<T, E> to R without unwrapping.

§serialize: bool

Serialize 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: bool

call_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: ReturnPref

Preferred 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: bool

Strict output conversion: panic instead of lossy widening for i64/u64/isize/usize.

§internal: bool

Mark as internal: adds @keywords internal, suppresses @export.

§noexport: bool

Suppress @export without adding @keywords internal.

§export: bool

Force @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

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

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 prefer or c_symbol)
  • Missing required sub-options (e.g., s3(...) without class)
Source§

fn parse(input: ParseStream<'_>) -> Result<Self>

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> SizeHint for T
where T: ?Sized,

Source§

default fn lower_bound(&self) -> usize

🔬This is a nightly-only experimental API. (core_io_internals)
Returns a lower bound on the number of elements this container-like item contains. For example, an array [u8; 12] could return any value between 0 and 12 inclusively as a correct implementation. Read more
Source§

default fn upper_bound(&self) -> Option<usize>

🔬This is a nightly-only experimental API. (core_io_internals)
Returns an upper bound on the number of elements this container-like item contains if it can be determined, otherwise None. Read more
Source§

final fn size_hint(&self) -> (usize, Option<usize>)

🔬This is a nightly-only experimental API. (core_io_internals)
Returns an estimate for the number of elements this container like type contains. Read more
Source§

impl<T> SizedTypeProperties for T

Source§

#[doc(hidden)]
const SIZE: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)]
const ALIGN: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)]
const ALIGNMENT: Alignment = _

🔬This is a nightly-only experimental API. (ptr_alignment_type)
Source§

#[doc(hidden)]
const IS_ZST: bool = _

🔬This is a nightly-only experimental API. (sized_type_properties)
true if this type requires no storage. false if its size is greater than zero. Read more
Source§

#[doc(hidden)]
const LAYOUT: Layout = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)]
const MAX_SLICE_LEN: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
The largest safe length for a [Self]. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.

Layout§

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