Skip to main content

Dots

Struct Dots 

Source
pub struct Dots {
    pub inner: SEXP,
}
Expand description

Rust type representing R’s ... (variadic arguments).

The generated R wrapper captures ... as list(...) and passes it to Rust, so Dots holds a list SEXP. Use as_list or try_list to access elements by name or position.

Declare it as a &Dots parameter at any position, one per function: fn foo(x: i32, rest: &Dots, flag: bool) becomes the R formals x, ..., flag, and parameters after it are matched by name only in R. Rust ... (or name: ...) is the same as a trailing &Dots parameter.

Fields§

§inner: SEXP

Raw list backing this ... capture.

This is usually a VECSXP built from list(...) by generated wrappers.

Implementations§

Source§

impl Dots

Source

pub fn empty() -> Self

Create an empty Dots (equivalent to no ... arguments).

This is useful when calling R functions from Rust that expect dots arguments but you want to pass nothing.

§Example
ⓘ
#[miniextendr]
pub fn my_constructor(x: Doubles, dots: ...) -> Robj {
    // ...
}

// Call from Rust with empty dots:
let result = my_constructor(data, Dots::empty());
Source

pub fn as_list(&self) -> List

Convert to a List without additional validation.

This is a zero-cost conversion since the R wrapper already passes list(...) to us. Use this when you trust the input or want maximum performance.

§Safety Note

This is safe because the miniextendr macro always wraps ... in list(...) on the R side. However, if you’re receiving a SEXP from another source, use try_list instead.

§Example
ⓘ
#[miniextendr]
pub fn process_dots(dots: ...) -> i32 {
    let list = dots.as_list();
    list.len() as i32
}
Source

pub fn try_list(&self) -> Result<List, SexpTypeError>

Convert to a List, checking that the underlying SEXP is a list.

Accepts a list (VECSXP) only, as TryFromSexp for List does; a pairlist is refused (#1866). Use this when inner may not come from a generated wrapper’s list(...).

Names are not checked: R lets the caller repeat a name in ... (f(a = 1, a = 2)). To refuse that, check List::first_duplicate_name; a typed spec refuses repeated names itself.

§Errors

Returns SexpTypeError if the SEXP is not a list.

§Example
ⓘ
#[miniextendr]
pub fn count_named_dots(dots: ...) -> Result<i32, String> {
    let list = dots.try_list().map_err(|e| e.to_string())?;
    if let Some(name) = list.first_duplicate_name() {
        return Err(format!("argument {name:?} was given more than once"));
    }
    Ok(list.len() as i32)
}
Source

pub fn len(&self) -> isize

Get the number of elements in the dots list.

This is equivalent to dots.as_list().len() but avoids creating an intermediate List wrapper.

Source

pub fn is_empty(&self) -> bool

Returns true if no arguments were passed to ....

Source

pub fn typed(&self, spec: TypedListSpec) -> Result<TypedList, TypedListError>

Validate the dots against a typed list specification.

This provides structured validation with clear error messages for functions that expect specific named arguments via ....

§Example
ⓘ
use miniextendr_api::typed_list::{TypedListSpec, TypedEntry, TypeSpec};

#[miniextendr]
pub fn process_args(dots: ...) -> Result<i32, String> {
    let spec = TypedListSpec::new(vec![
        TypedEntry::required("alpha", TypeSpec::Numeric(Some(4))),
        TypedEntry::optional("beta", TypeSpec::List(None)),
    ]);

    let validated = dots.typed(spec).map_err(|e| e.to_string())?;
    let alpha: Vec<f64> = validated.get("alpha").map_err(|e| e.to_string())?;
    Ok(alpha.len() as i32)
}
§Errors

Returns TypedListError if:

  • The dots are not a valid list
  • A required field is missing
  • A field has the wrong type or length
  • Extra fields exist when allow_extra = false

Trait Implementations§

Source§

impl Debug for Dots

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Dots

§

impl RefUnwindSafe for Dots

§

impl Send for Dots

§

impl Sync for Dots

§

impl Unpin for Dots

§

impl UnsafeUnpin for Dots

§

impl UnwindSafe for Dots

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> RDebug for T
where T: Debug,

Source§

fn debug_str(&self) -> String

Get a compact debug string representation.
Source§

fn debug_str_pretty(&self) -> String

Get a pretty-printed debug string with indentation.
Source§

#[doc(hidden)]
unsafe extern "C" fn __RDebug_debug_str_shim( data: *mut c_void, argc: i32, argv: *const SEXP, ) -> SEXP
where Self: Sized + RDebug,

Method shim for RDebug::debug_str. Read more
Source§

#[doc(hidden)]
unsafe extern "C" fn __RDebug_debug_str_pretty_shim( data: *mut c_void, argc: i32, argv: *const SEXP, ) -> SEXP
where Self: Sized + RDebug,

Method shim for RDebug::debug_str_pretty. Read more
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: 8 bytes