pub struct NamedListBuilder {
values: Preserved,
names: Vec<String>,
}Expand description
A safe, owned builder for a named R list of mixed IntoR values.
One growing VECSXP holds the values and is rooted by a Preserved handle.
Moving or dropping builders in any order is safe: no protect-stack entries
are held by the builder, regardless of the number of values pushed.
Construction, use and drop must take place on R’s main thread (!Send + !Sync).
Return the builder from a #[miniextendr] function to return a named list.
To keep working with the finished value while R allocates (set a class,
pass it to R code, read it back), consume it with
into_list for a rooted BuiltList, or with
into_data_frame for a rooted data frame. Empty
results have names = character(0). There is no bare List
finish.
let mut columns = NamedListBuilder::with_capacity(2);
columns.push("id", vec![1, 2, 3]);
columns.push("value", vec![0.5, 1.5, 2.5]);
columns.rename(1, "estimate");
let frame = columns.into_data_frame()?;Fields§
§values: Preserved§names: Vec<String>Implementations§
Source§impl NamedListBuilder
impl NamedListBuilder
Sourcepub fn with_capacity(n: usize) -> Self
pub fn with_capacity(n: usize) -> Self
Reserve space for n entries on R’s main thread.
Sourcepub fn push(&mut self, name: impl Into<String>, value: impl IntoR)
pub fn push(&mut self, name: impl Into<String>, value: impl IntoR)
Convert and append a value, rooting it before any later allocation.
Sourcepub fn push_sexp(&mut self, name: impl Into<String>, sexp: SEXP)
pub fn push_sexp(&mut self, name: impl Into<String>, sexp: SEXP)
Append an existing R value, retaining its attributes and identity.
The value must be live when passed in. A freshly allocated, unrooted value can be passed directly: even when growth is needed it is rooted before the allocation. The builder then keeps it alive independently of the caller’s roots.
Sourcepub fn rename(&mut self, index: usize, name: impl Into<String>)
pub fn rename(&mut self, index: usize, name: impl Into<String>)
Rename the entry at the zero-based index.
Panics if the index is outside 0..self.len().
Sourcepub fn names_mut(&mut self) -> &mut [String]
pub fn names_mut(&mut self) -> &mut [String]
Edit names without changing the number or order of values.
Sourcepub fn into_list(self) -> BuiltList
pub fn into_list(self) -> BuiltList
Finish as an owned, GC-rooted named list.
The BuiltList keeps the list reachable while it lives, so its
attributes can be set and it can be handed to R code before it is
returned.
Sourcepub fn into_data_frame(self) -> Result<BuiltDataFrame, DataFrameError>
pub fn into_data_frame(self) -> Result<BuiltDataFrame, DataFrameError>
Finish as an owned, GC-rooted data frame with compact row.names.
Returns DataFrameError::UnequalLengths naming every column whose
length differs from the first. No recycling is performed. Zero columns
produce a zero-row frame with names = character(0).
Sourcefn resize(&mut self, capacity: usize)
fn resize(&mut self, capacity: usize)
Reallocate, keeping both containers rooted until copying is complete.
fn finish(&mut self)
Trait Implementations§
Source§impl Default for NamedListBuilder
impl Default for NamedListBuilder
Source§impl IntoR for NamedListBuilder
impl IntoR for NamedListBuilder
Source§fn try_into_sexp(self) -> Result<SEXP, Self::Error>
fn try_into_sexp(self) -> Result<SEXP, Self::Error>
Source§unsafe fn try_into_sexp_unchecked(self) -> Result<SEXP, Self::Error>
unsafe fn try_into_sexp_unchecked(self) -> Result<SEXP, Self::Error>
Auto Trait Implementations§
impl !Send for NamedListBuilder
impl !Sync for NamedListBuilder
impl Freeze for NamedListBuilder
impl RefUnwindSafe for NamedListBuilder
impl Unpin for NamedListBuilder
impl UnsafeUnpin for NamedListBuilder
impl UnwindSafe for NamedListBuilder
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> 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: 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: 32 bytes