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::Dotsargument_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: ItemFnThe normalized function item (with dots transformed, wildcards renamed).
has_dots: boolWhether 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.
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.
Sourcepub(crate) fn named_dots(&self) -> Option<&Ident>
pub(crate) fn named_dots(&self) -> Option<&Ident>
If dots were named (e.g., my_dots: ...), returns the identifier.
Sourcepub(crate) fn is_dots_param(&self, ident: &Ident) -> bool
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.
Sourcepub(crate) fn has_coerce_attr(&self, param_name: &str) -> bool
pub(crate) fn has_coerce_attr(&self, param_name: &str) -> bool
Check if a parameter name had #[miniextendr(coerce)] attribute.
Sourcepub(crate) fn has_match_arg_attr(&self, param_name: &str) -> bool
pub(crate) fn has_match_arg_attr(&self, param_name: &str) -> bool
Check if a parameter name had #[miniextendr(match_arg)] attribute.
Sourcepub(crate) fn match_arg_params(&self) -> impl Iterator<Item = &String>
pub(crate) fn match_arg_params(&self) -> impl Iterator<Item = &String>
Iterator over parameter names annotated with #[miniextendr(match_arg)].
Sourcepub(crate) fn choices_for_param(&self, param_name: &str) -> Option<&[String]>
pub(crate) fn choices_for_param(&self, param_name: &str) -> Option<&[String]>
Get the choices for a parameter, if any.
Sourcepub(crate) fn choices_params(
&self,
) -> impl Iterator<Item = (&String, &Vec<String>)>
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.
Sourcepub(crate) fn has_several_ok(&self, param_name: &str) -> bool
pub(crate) fn has_several_ok(&self, param_name: &str) -> bool
Check if a parameter has several_ok (multi-value match.arg).
Sourcepub(crate) fn param_defaults(&self) -> HashMap<String, String>
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\"").
Sourcepub(crate) fn attrs(&self) -> &[Attribute]
pub(crate) fn attrs(&self) -> &[Attribute]
Original attributes on the function item (doc comments, cfgs, etc.).
Sourcepub(crate) fn vis(&self) -> &Visibility
pub(crate) fn vis(&self) -> &Visibility
Visibility of the function (pub, pub(crate), or private).
Sourcepub(crate) fn abi(&self) -> Option<&Abi>
pub(crate) fn abi(&self) -> Option<&Abi>
Explicit ABI, if the function was declared extern "C-unwind".
Sourcepub(crate) fn inputs(&self) -> &Punctuated<FnArg, Comma>
pub(crate) fn inputs(&self) -> &Punctuated<FnArg, Comma>
Function inputs after normalization (dots rewritten, wildcards renamed).
Sourcepub(crate) fn output(&self) -> &ReturnType
pub(crate) fn output(&self) -> &ReturnType
Function return type.
Sourcepub(crate) fn item(&self) -> &ItemFn
pub(crate) fn item(&self) -> &ItemFn
The normalized function item (with original doc comments).
Sourcepub(crate) fn item_without_roxygen(&self) -> ItemFn
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.
Sourcepub(crate) fn uses_internal_c_wrapper(&self) -> bool
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.
Sourcepub(crate) fn r_wrapper_const_ident(&self) -> Ident
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.
Sourcepub(crate) fn c_wrapper_ident(&self) -> Ident
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.
Sourcepub(crate) fn export_name_ident(&self) -> Option<Ident>
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.
Sourcepub(crate) fn add_track_caller_if_needed(&mut self)
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.
Sourcepub(crate) fn add_inline_never_if_needed(&mut self)
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.
impl Parse for MiniextendrFunctionParsed
Parses a Rust fn item from a token stream, performing all normalizations
required by the #[miniextendr] codegen pipeline.
§Normalizations performed
- Variadic (
...) rewriting: Replaces Rust variadic syntax with a typed&miniextendr_api::dots::Dotsparameter. Named dots (my_dots: ...) preserve the user’s identifier; unnamed...becomes__miniextendr_dots. - Wildcard pattern renaming:
_parameter patterns become__unused0,__unused1, etc., so they can be passed by name to the C wrapper. - Destructuring expansion: Tuple/struct destructuring patterns are replaced
with synthetic identifiers (
__param_0, …) and aletbinding is prepended to the function body. - Per-parameter attribute consumption:
#[miniextendr(coerce)],#[miniextendr(match_arg)],#[miniextendr(default = "...")], and#[miniextendr(choices(...))]are consumed from parameters and recorded in the correspondingper_param_*fields. - Validation: Rejects
#[export_name]on non-extern functions, rejects unsupported parameter patterns, and validates that defaults reference existing parameter names.
fn parse(input: ParseStream<'_>) -> Result<Self>
Auto Trait Implementations§
impl Freeze for MiniextendrFunctionParsed
impl RefUnwindSafe for MiniextendrFunctionParsed
impl !Send for MiniextendrFunctionParsed
impl !Sync for MiniextendrFunctionParsed
impl Unpin for MiniextendrFunctionParsed
impl UnsafeUnpin for MiniextendrFunctionParsed
impl UnwindSafe for MiniextendrFunctionParsed
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> 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: 552 bytes