Skip to main content

RFromIter

Trait RFromIter 

Source
pub trait RFromIter<T>: Sized {
    // Required method
    fn from_vec(items: Vec<T>) -> Self;
}
Expand description

Adapter trait for std::iter::FromIterator.

Provides collection construction from iterators/vectors for R. Unlike RExtend, this creates a new collection from items.

§Methods

  • from_vec(items) - Create a new collection from a vector

§Example

#[derive(ExternalPtr)]
struct MySet(std::collections::HashSet<i32>);

impl RFromIter<i32> for MySet {
    fn from_vec(items: Vec<i32>) -> Self {
        Self(items.into_iter().collect())
    }
}

#[miniextendr]
impl RFromIter<i32> for MySet {}

In R:

set <- MySet$from_vec(c(1L, 2L, 2L, 3L))  # Creates {1, 2, 3}

Required Methods§

Source

fn from_vec(items: Vec<T>) -> Self

Create a new collection from a vector of items.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<C, T> RFromIter<T> for C
where C: FromIterator<T>,