Skip to main content

MiniextendrFunctionParsed

Struct MiniextendrFunctionParsed 

Source
pub(crate) struct MiniextendrFunctionParsed {
    item: ItemFn,
    has_dots: bool,
    named_dots: Option<Ident>,
    per_param: HashMap<String, ParamAttrs>,
}
Expand description

Parsed + normalized Rust function item for #[miniextendr].

This performs signature normalization that the wrapper generator depends on:

  • ... → a final &miniextendr_api::dots::Dots argument
  • _ wildcard patterns → synthetic identifiers (__unused0, __unused1, …)
  • Destructuring patterns (tuple, struct) → synthetic identifiers with let-binding in body
  • consumes #[miniextendr(coerce)] parameter attributes and records which params had it

Fields§

§item: ItemFn

The normalized function item (with dots transformed, wildcards renamed).

§has_dots: bool

Whether the original function had ... (variadic).

§named_dots: Option<Ident>

If dots were named (e.g., my_dots: ...), the identifier.

§per_param: HashMap<String, ParamAttrs>

All per-parameter #[miniextendr(...)] options (coerce, match_arg, default, choices, several_ok), keyed by the (possibly synthesized) Rust parameter name. Replaces five parallel HashSet / HashMap fields.

Implementations§

Source§

impl MiniextendrFunctionParsed

Accessors and codegen helpers for MiniextendrFunctionParsed.

Accessors are split into two groups:

  • Parsed metadata: dots, coerce, match_arg, choices, and defaults from per-parameter #[miniextendr(...)] attributes.
  • Signature components: attrs, vis, abi, ident, generics, inputs, output from the normalized syn::ItemFn.

Codegen helpers produce identifiers and perform mutations needed by the #[miniextendr] expansion pipeline.

Source

pub(crate) fn has_dots(&self) -> bool

Whether the original function had ... (variadic).

Source

pub(crate) fn named_dots(&self) -> Option<&Ident>

If dots were named (e.g., my_dots: ...), returns the identifier.

Source

pub(crate) fn is_dots_param(&self, ident: &Ident) -> bool

Check if a parameter is the dots (...) param. After parsing, dots are rewritten to &Dots — this checks the original name.

Source

pub(crate) fn has_coerce_attr(&self, param_name: &str) -> bool

Check if a parameter name had #[miniextendr(coerce)] attribute.

Source

pub(crate) fn has_match_arg_attr(&self, param_name: &str) -> bool

Check if a parameter name had #[miniextendr(match_arg)] attribute.

Source

pub(crate) fn match_arg_params(&self) -> impl Iterator<Item = &String>

Iterator over parameter names annotated with #[miniextendr(match_arg)].

Source

pub(crate) fn choices_for_param(&self, param_name: &str) -> Option<&[String]>

Get the choices for a parameter, if any.

Source

pub(crate) fn choices_params( &self, ) -> impl Iterator<Item = (&String, &Vec<String>)>

Iterator over parameter names annotated with #[miniextendr(choices(…))], together with their choice lists.

Source

pub(crate) fn has_several_ok(&self, param_name: &str) -> bool

Check if a parameter has several_ok (multi-value match.arg).

Source

pub(crate) fn param_defaults(&self) -> HashMap<String, String>

Returns all parameter defaults as an owned map from parameter name to default value string (the raw R expression used in the wrapper formals, e.g. "NULL", "TRUE", "\"Safe\"").

Source

pub(crate) fn attrs(&self) -> &[Attribute]

Original attributes on the function item (doc comments, cfgs, etc.).

Source

pub(crate) fn vis(&self) -> &Visibility

Visibility of the function (pub, pub(crate), or private).

Source

pub(crate) fn abi(&self) -> Option<&Abi>

Explicit ABI, if the function was declared extern "C-unwind".

Source

pub(crate) fn ident(&self) -> &Ident

Function identifier after normalization.

Source

pub(crate) fn generics(&self) -> &Generics

Generic parameters on the function signature.

Source

pub(crate) fn inputs(&self) -> &Punctuated<FnArg, Comma>

Function inputs after normalization (dots rewritten, wildcards renamed).

Source

pub(crate) fn output(&self) -> &ReturnType

Function return type.

Source

pub(crate) fn item(&self) -> &ItemFn

The normalized function item (with original doc comments).

Source

pub(crate) fn item_without_roxygen(&self) -> ItemFn

The normalized function item with roxygen tags stripped from doc comments.

This is used for emitting the Rust function without R-specific documentation tags (e.g., @param, @examples) that don’t belong in rustdoc.

Source

pub(crate) fn uses_internal_c_wrapper(&self) -> bool

Returns true if this function needs an internal C wrapper (C_<name> function).

Rust-ABI functions (no explicit extern) need a generated extern "C-unwind" wrapper that handles SEXP conversion and error propagation. Functions already declared as extern "C-unwind" are passed through directly without wrapping.

Source

pub(crate) fn r_wrapper_const_ident(&self) -> Ident

Returns the identifier for the generated const &str holding the R wrapper code.

The R wrapper is a string constant containing the R function definition that calls .Call(C_<name>, ...). It is collected via linkme distributed slices to produce the R/miniextendr_wrappers.R file.

Source

pub(crate) fn c_wrapper_ident(&self) -> Ident

Returns the identifier for the C-callable entry point.

  • Rust ABI functions: Returns C_<name> (the generated wrapper function).
  • extern "C-unwind" functions: Returns the function’s own name, or the value from #[export_name = "..."] if present.
Source

pub(crate) fn export_name_ident(&self) -> Option<Ident>

Extracts the custom symbol name from #[export_name = "..."], if present.

Only meaningful for extern "C-unwind" functions, where #[export_name] is allowed as an alternative to #[no_mangle]. Returns None if no such attribute exists.

Source

pub(crate) fn add_track_caller_if_needed(&mut self)

Add #[track_caller] if not already present (for better panic locations). Only for Rust ABI functions - extern “C-unwind” doesn’t support track_caller.

Source

pub(crate) fn add_inline_never_if_needed(&mut self)

Add #[inline(never)] if no #[inline(...)] attribute is present. Only for Rust ABI functions - extern “C-unwind” functions are passed through as-is.

Preventing inlining ensures:

  • The worker thread pattern works correctly (function runs in separate context)
  • Panic handling and unwinding work as expected
  • Stack traces show the actual function name

Trait Implementations§

Source§

impl Parse for MiniextendrFunctionParsed

Parses a Rust fn item from a token stream, performing all normalizations required by the #[miniextendr] codegen pipeline.

§Normalizations performed

  1. Variadic (...) rewriting: Replaces Rust variadic syntax with a typed &miniextendr_api::dots::Dots parameter. Named dots (my_dots: ...) preserve the user’s identifier; unnamed ... becomes __miniextendr_dots.
  2. Wildcard pattern renaming: _ parameter patterns become __unused0, __unused1, etc., so they can be passed by name to the C wrapper.
  3. Destructuring expansion: Tuple/struct destructuring patterns are replaced with synthetic identifiers (__param_0, …) and a let binding is prepended to the function body.
  4. Per-parameter attribute consumption: #[miniextendr(coerce)], #[miniextendr(match_arg)], #[miniextendr(default = "...")], and #[miniextendr(choices(...))] are consumed from parameters and recorded in the corresponding per_param_* fields.
  5. Validation: Rejects #[export_name] on non-extern functions, rejects unsupported parameter patterns, and validates that defaults reference existing parameter names.
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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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: 552 bytes