pub trait RToVec<T> {
// Required methods
fn to_vec(&self) -> Vec<T>;
fn len(&self) -> i64;
// Provided method
fn is_empty(&self) -> bool { ... }
}Expand description
Adapter trait for collections that can be converted to vectors.
This is the complement to RFromIter: while RFromIter creates collections
from vectors, RToVec extracts vectors from collections.
§Methods
to_vec()- Collect all elements into a vector (cloning elements)len()- Get the number of elementsis_empty()- Check if the collection is empty
§Design Note
Unlike Rust’s IntoIterator::into_iter() which consumes the collection,
this trait borrows the collection and clones elements. This is necessary
because R’s ExternalPtr pattern provides &self, not owned self.
For consuming iteration, use RIterator with interior mutability.
§Example
ⓘ
use std::collections::HashSet;
#[derive(ExternalPtr)]
struct MySet(HashSet<i32>);
// RToVec is automatically available via blanket impl
#[miniextendr]
impl RToVec<i32> for MySet {}In R:
set <- MySet$new(...)
vec <- set$to_vec() # Get all elements as vector
set$len() # Number of elements
set$is_empty() # Check if empty