Skip to main content

NamedListBuilder

Struct NamedListBuilder 

Source
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

Source

pub fn new() -> Self

Create an empty builder on R’s main thread.

Source

pub fn with_capacity(n: usize) -> Self

Reserve space for n entries on R’s main thread.

Source

pub fn push(&mut self, name: impl Into<String>, value: impl IntoR)

Convert and append a value, rooting it before any later allocation.

Source

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.

Source

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().

Source

pub fn names(&self) -> &[String]

Entry names in insertion order.

Source

pub fn names_mut(&mut self) -> &mut [String]

Edit names without changing the number or order of values.

Source

pub fn len(&self) -> usize

Number of entries pushed so far.

Source

pub fn is_empty(&self) -> bool

Whether no entries have been pushed.

Source

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.

Source

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).

Source

fn resize(&mut self, capacity: usize)

Reallocate, keeping both containers rooted until copying is complete.

Source

fn finish(&mut self)

Trait Implementations§

Source§

impl Default for NamedListBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl IntoR for NamedListBuilder

Source§

type Error = !

The error type for fallible conversions. Read more
Source§

fn try_into_sexp(self) -> Result<SEXP, Self::Error>

Try to convert this value to an R SEXP. Read more
Source§

unsafe fn try_into_sexp_unchecked(self) -> Result<SEXP, Self::Error>

Try to convert to SEXP without thread safety checks. Read more
Source§

fn into_sexp(self) -> SEXP
where Self: Sized,

Convert this value to an R SEXP, panicking on error. Read more
Source§

unsafe fn into_sexp_unchecked(self) -> SEXP
where Self: Sized,

Convert to SEXP without thread safety checks, panicking on error. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> RDefault for T
where T: Default,

Source§

fn r_default() -> T

Create a new instance with default values.
Source§

impl<T> SizeHint for T
where T: ?Sized,

Source§

default fn lower_bound(&self) -> usize

🔬This is a nightly-only experimental API. (core_io_internals)
Returns a lower bound on the number of elements this container-like item contains. For example, an array [u8; 12] could return any value between 0 and 12 inclusively as a correct implementation. Read more
Source§

default fn upper_bound(&self) -> Option<usize>

🔬This is a nightly-only experimental API. (core_io_internals)
Returns an upper bound on the number of elements this container-like item contains if it can be determined, otherwise None. Read more
Source§

final fn size_hint(&self) -> (usize, Option<usize>)

🔬This is a nightly-only experimental API. (core_io_internals)
Returns an estimate for the number of elements this container like type contains. Read more
Source§

impl<T> SizedTypeProperties for T

Source§

#[doc(hidden)]
const SIZE: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)]
const ALIGN: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)]
const ALIGNMENT: Alignment = _

🔬This is a nightly-only experimental API. (ptr_alignment_type)
Source§

#[doc(hidden)]
const IS_ZST: bool = _

🔬This is a nightly-only experimental API. (sized_type_properties)
true if this type requires no storage. false if its size is greater than zero. Read more
Source§

#[doc(hidden)]
const LAYOUT: Layout = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)]
const MAX_SLICE_LEN: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
The largest safe length for a [Self]. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.

Layout§

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