pub struct AsNamedList<T>(pub T);Expand description
Wrap a tuple pair collection and convert it to a named R list (VECSXP).
Preserves insertion order and allows duplicate names (sequence semantics).
§Supported input types
| Input | Bounds |
|---|---|
Vec<(K, V)> | K: AsRef<str>, V: IntoR |
[(K, V); N] | K: AsRef<str>, V: IntoR |
&[(K, V)] | K: AsRef<str>, V: Clone + IntoR |
§GC safety — use typed values, never raw SEXP (#1030)
Prefer typed value types (i32, String, Vec<T>, …) over raw
crate::SEXP. With a typed V, each value’s into_sexp() runs inside
AsNamedList::into_sexp, immediately before the value is
protected and placed into the list — no allocation ever fires while a sibling
value sits unprotected.
A raw SEXP value (V = SEXP) is GC-fragile and must not be used. The
caller has to build the SEXP values in an earlier frame (each into_sexp()
allocates) and then hand them to AsNamedList; the deferred from_raw_pairs
runs later, in the generated wrapper, so there is no call site at which a
ProtectScope can span both value construction and the deferred list build.
The internal protection added in into_sexp (below) closes the receipt →
from_raw_pairs window but cannot retroactively protect values that were
already built and unrooted in the caller — that construction window is the
latent use-after-free. Stable Rust cannot exclude one concrete type from a
V: IntoR blanket, so this is enforced by convention (and the MXL302 lint on
the into_sexp()-in-vec! idiom) rather than the type system; passing typed
values sidesteps the hazard entirely.
§Example
#[miniextendr]
fn make_config() -> AsNamedList<Vec<(String, i32)>> {
AsNamedList(vec![
("width".into(), 100),
("height".into(), 200),
])
}
// In R: make_config() returns list(width = 100L, height = 200L)Tuple Fields§
§0: TTrait Implementations§
Source§impl<T: Clone> Clone for AsNamedList<T>
impl<T: Clone> Clone for AsNamedList<T>
Source§fn clone(&self) -> AsNamedList<T>
fn clone(&self) -> AsNamedList<T>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T: Debug> Debug for AsNamedList<T>
impl<T: Debug> Debug for AsNamedList<T>
Source§impl<T> From<T> for AsNamedList<T>
impl<T> From<T> for AsNamedList<T>
Source§impl<K: AsRef<str>, V: IntoR> IntoR for AsNamedList<Vec<(K, V)>>
impl<K: AsRef<str>, V: IntoR> IntoR for AsNamedList<Vec<(K, V)>>
Source§type Error = Infallible
type Error = Infallible
Source§fn try_into_sexp(self) -> Result<SEXP, Self::Error>
fn try_into_sexp(self) -> Result<SEXP, Self::Error>
Source§impl<K: AsRef<str>, V: IntoR, const N: usize> IntoR for AsNamedList<[(K, V); N]>
impl<K: AsRef<str>, V: IntoR, const N: usize> IntoR for AsNamedList<[(K, V); N]>
Source§type Error = Infallible
type Error = Infallible
Source§fn try_into_sexp(self) -> Result<SEXP, Self::Error>
fn try_into_sexp(self) -> Result<SEXP, Self::Error>
Source§impl<K: AsRef<str>, V: Clone + IntoR> IntoR for AsNamedList<&[(K, V)]>
impl<K: AsRef<str>, V: Clone + IntoR> IntoR for AsNamedList<&[(K, V)]>
Source§type Error = Infallible
type Error = Infallible
Source§fn try_into_sexp(self) -> Result<SEXP, Self::Error>
fn try_into_sexp(self) -> Result<SEXP, Self::Error>
Auto Trait Implementations§
impl<T> Freeze for AsNamedList<T>where
T: Freeze,
impl<T> RefUnwindSafe for AsNamedList<T>where
T: RefUnwindSafe,
impl<T> Send for AsNamedList<T>where
T: Send,
impl<T> Sync for AsNamedList<T>where
T: Sync,
impl<T> Unpin for AsNamedList<T>where
T: Unpin,
impl<T> UnsafeUnpin for AsNamedList<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for AsNamedList<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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> SizeHint for Twhere
T: ?Sized,
impl<T> SizeHint for Twhere
T: ?Sized,
Source§default fn lower_bound(&self) -> usize
default fn lower_bound(&self) -> usize
core_io_internals)[u8; 12] could return any value between 0 and
12 inclusively as a correct implementation. Read moreSource§impl<T> SizedTypeProperties for T
impl<T> SizedTypeProperties for T
Source§#[doc(hidden)]const SIZE: usize = _
#[doc(hidden)]const SIZE: usize = _
sized_type_properties)Source§#[doc(hidden)]const ALIGN: usize = _
#[doc(hidden)]const ALIGN: usize = _
sized_type_properties)Source§#[doc(hidden)]const ALIGNMENT: Alignment = _
#[doc(hidden)]const ALIGNMENT: Alignment = _
ptr_alignment_type)Source§#[doc(hidden)]const IS_ZST: bool = _
#[doc(hidden)]const IS_ZST: bool = _
sized_type_properties)Source§#[doc(hidden)]const LAYOUT: Layout = _
#[doc(hidden)]const LAYOUT: Layout = _
sized_type_properties)Source§#[doc(hidden)]const MAX_SLICE_LEN: usize = _
#[doc(hidden)]const MAX_SLICE_LEN: usize = _
sized_type_properties)[Self]. Read moreLayout§
Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.