Skip to main content

RArgumentBuilder

Struct RArgumentBuilder 

Source
pub struct RArgumentBuilder<'a> {
    inputs: &'a Punctuated<FnArg, Comma>,
    dots_index: Option<usize>,
    dots_kind: Option<DotsKind>,
    skip_first: bool,
    defaults: HashMap<String, String>,
    absent_formals: HashMap<String, String>,
    formals: Formals,
}
Expand description

Builder for R function formal parameters and call arguments.

Handles:

  • R formals: the declared formal = ".." (#1842), else the Rust name without leading underscores (_x → x)
  • Unit type defaults (() → = NULL)
  • Dots: the &Dots parameter is ... in the formals and list(...) in the call arguments, at its own position in the signature; a LazyDots parameter is ... too, and environment() in the call arguments, which passes the dots unforced (#1892)
  • The argument count: an NArgs parameter is no formal and nargs() in the call arguments, at its own position (#1860)
  • Consistent formatting across function and method wrappers

Fields§

§inputs: &'a Punctuated<FnArg, Comma>

The function’s input parameters from the parsed Rust signature.

§dots_index: Option<usize>

Position of the &Dots / LazyDots parameter in inputs (receiver included, the way both build loops count). Its Rust name never reaches R: the formal is always plain ....

§dots_kind: Option<DotsKind>

Which ... type it is: what the call arguments pass at its position.

§skip_first: bool

If true, skip the first parameter (used for self/&self in method wrappers, since the self argument is handled separately by DotCallBuilder::with_self).

§defaults: HashMap<String, String>

Parameter default values from #[miniextendr(default = "...")] attributes. Keys are R formals (Formals::of), values are R expressions emitted verbatim (e.g., "1L", "c(1, 2, 3)", "NULL").

§absent_formals: HashMap<String, String>

The single-choice Missing<..> parameters that read a value identical() to their formal as omitted (#2152), R formal → the formal’s default (see crate::miniextendr_fn::ParamAttrs::absent_formal).

§formals: Formals

The R formal of each parameter (#1842).

Implementations§

Source§

impl<'a> RArgumentBuilder<'a>

Source

pub fn new(inputs: &'a Punctuated<FnArg, Comma>) -> Self

Create a new builder for the given function inputs.

Source

pub fn with_formals(self, formals: Formals) -> Self

Name each parameter by its R formal (#1842): the declared formal = "..", else the normalized Rust name (the default). The keys of Self::with_defaults and Self::with_absent_formals are these formals.

Source

pub fn with_absent_formals( self, absent_formals: HashMap<String, String>, ) -> Self

Add the Missing<..> choice parameters that read a value identical() to their formal as omitted (#2152), keyed by R formal, valued by that formal’s default (see crate::miniextendr_fn::absent_formals_by_r_name).

Source

pub fn with_defaults(self, defaults: HashMap<String, String>) -> Self

Add parameter defaults from #[miniextendr(default = "...")] attributes.

Keys are R formals (see Self::with_formals; without a declared formal, the Rust name without leading underscores), values are R expression strings emitted verbatim into formals.

Source

pub fn skip_first(self) -> Self

Skip the first parameter (for instance methods with self).

Source

pub fn build_formals(&self) -> String

Build R formal parameters string (for function signature).

§Returns

Comma-separated parameter list, e.g., "x, y = NULL, ..."

This method handles R-style defaults (like 1L, c(1,2,3)) that aren’t valid Rust syntax by outputting them directly as strings.

Source

pub fn build_call_args(&self) -> String

Build R call arguments string (for .Call() invocation).

§Returns

Comma-separated argument list, e.g., "x, y, list(...)" (or "x, y, environment()" for a LazyDots parameter)

Source

pub fn build_call_args_vec(&self) -> Vec<String>

Build R call arguments as a Vec<String>.

Each element is a single argument expression. A &Dots parameter becomes "list(...)", which captures the variadic args as an R list for the .Call() interface; a LazyDots parameter becomes "environment()", the wrapper’s own frame, whose ... binding holds the dots unforced (#1892).

Auto Trait Implementations§

§

impl<'a> !Send for RArgumentBuilder<'a>

§

impl<'a> !Sync for RArgumentBuilder<'a>

§

impl<'a> Freeze for RArgumentBuilder<'a>

§

impl<'a> RefUnwindSafe for RArgumentBuilder<'a>

§

impl<'a> Unpin for RArgumentBuilder<'a>

§

impl<'a> UnsafeUnpin for RArgumentBuilder<'a>

§

impl<'a> UnwindSafe for RArgumentBuilder<'a>

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