pub struct AsNamedVector<T>(pub T);Expand description
Wrap a tuple pair collection and convert it to a named atomic R vector (INTSXP, REALSXP, LGLSXP, RAWSXP, or STRSXP).
Preserves insertion order and allows duplicate names (sequence semantics).
Values must be homogeneous and implement AtomicElement.
§Supported input types
| Input | Bounds |
|---|---|
Vec<(K, V)> | K: AsRef<str>, V: AtomicElement |
[(K, V); N] | K: AsRef<str>, V: AtomicElement |
&[(K, V)] | K: AsRef<str>, V: Clone + AtomicElement |
§Example
ⓘ
#[miniextendr]
fn make_scores() -> AsNamedVector<Vec<(&str, f64)>> {
AsNamedVector(vec![("alice", 95.0), ("bob", 87.5)])
}
// In R: make_scores() returns c(alice = 95.0, bob = 87.5)Tuple Fields§
§0: TTrait Implementations§
Source§impl<T: Clone> Clone for AsNamedVector<T>
impl<T: Clone> Clone for AsNamedVector<T>
Source§fn clone(&self) -> AsNamedVector<T>
fn clone(&self) -> AsNamedVector<T>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<T: Debug> Debug for AsNamedVector<T>
impl<T: Debug> Debug for AsNamedVector<T>
Source§impl<T> From<T> for AsNamedVector<T>
impl<T> From<T> for AsNamedVector<T>
Source§impl<K: AsRef<str>, V: Clone + AtomicElement> IntoR for AsNamedVector<&[(K, V)]>
impl<K: AsRef<str>, V: Clone + AtomicElement> IntoR for AsNamedVector<&[(K, V)]>
Source§type Error = Infallible
type Error = Infallible
The error type for fallible conversions. Read more
Source§fn try_into_sexp(self) -> Result<SEXP, Self::Error>
fn try_into_sexp(self) -> Result<SEXP, Self::Error>
Try to convert this value to an R SEXP. Read more
Source§impl<K: AsRef<str>, V: AtomicElement, const N: usize> IntoR for AsNamedVector<[(K, V); N]>
impl<K: AsRef<str>, V: AtomicElement, const N: usize> IntoR for AsNamedVector<[(K, V); N]>
Source§type Error = Infallible
type Error = Infallible
The error type for fallible conversions. Read more
Source§fn try_into_sexp(self) -> Result<SEXP, Self::Error>
fn try_into_sexp(self) -> Result<SEXP, Self::Error>
Try to convert this value to an R SEXP. Read more
Source§impl<K: AsRef<str>, V: AtomicElement> IntoR for AsNamedVector<Vec<(K, V)>>
impl<K: AsRef<str>, V: AtomicElement> IntoR for AsNamedVector<Vec<(K, V)>>
Source§type Error = Infallible
type Error = Infallible
The error type for fallible conversions. Read more
Source§fn try_into_sexp(self) -> Result<SEXP, Self::Error>
fn try_into_sexp(self) -> Result<SEXP, Self::Error>
Try to convert this value to an R SEXP. Read more
Auto Trait Implementations§
impl<T> Freeze for AsNamedVector<T>where
T: Freeze,
impl<T> RefUnwindSafe for AsNamedVector<T>where
T: RefUnwindSafe,
impl<T> Send for AsNamedVector<T>where
T: Send,
impl<T> Sync for AsNamedVector<T>where
T: Sync,
impl<T> Unpin for AsNamedVector<T>where
T: Unpin,
impl<T> UnsafeUnpin for AsNamedVector<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for AsNamedVector<T>where
T: UnwindSafe,
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
Mutably borrows from an owned value. Read more