Skip to main content

ListBuilder

Struct ListBuilder 

Source
pub struct ListBuilder<'a> {
    list: SEXP,
    _scope: &'a ProtectScope,
}
Expand description

Builder for constructing lists with efficient protection management.

ListBuilder holds a reference to a ProtectScope, allowing multiple elements to be inserted without repeatedly protecting/unprotecting each one. This is more efficient than using List::set_elt in a loop.

§Example

unsafe fn build_list(n: isize) -> SEXP {
    let scope = ProtectScope::new();
    let builder = ListBuilder::new(&scope, n);

    for i in 0..n {
        // Allocations inside the loop are protected by the scope
        let child = scope.alloc_real(10).into_raw();
        builder.set(i, child);
    }

    builder.into_sexp()
}

Fields§

§list: SEXP§_scope: &'a ProtectScope

Implementations§

Source§

impl<'a> ListBuilder<'a>

Source

pub unsafe fn new(scope: &'a ProtectScope, len: usize) -> Self

Create a new list builder with the given length.

The list is allocated and protected using the provided scope.

§Safety

Must be called from the R main thread.

Source

pub unsafe fn from_protected(scope: &'a ProtectScope, list: SEXP) -> Self

Create a builder wrapping an existing protected list.

§Safety
  • Must be called from the R main thread
  • list must be a valid, protected VECSXP
Source

pub unsafe fn set(&self, idx: isize, child: SEXP)

Set an element at the given index.

The child should be protected by the same scope (or a parent scope). Use scope.protect_raw(...) before calling this method.

§Safety
  • child must be a valid SEXP
  • child should be protected (typically via the same scope)
Source

pub unsafe fn set_protected(&self, idx: isize, child: SEXP)

Set an element, protecting the child within the builder’s scope.

This is a convenience method that protects the child and then inserts it.

§Safety
  • child must be a valid SEXP
Source

pub fn as_sexp(&self) -> SEXP

Get the underlying list SEXP.

Source

pub fn into_list(self) -> List

Convert to a List wrapper.

Source

pub fn into_sexp(self) -> SEXP

Convert to the underlying SEXP.

Source

pub fn len(&self) -> isize

Get the length of the list.

Source

pub fn is_empty(&self) -> bool

Check if the list is empty.

Auto Trait Implementations§

§

impl<'a> Freeze for ListBuilder<'a>

§

impl<'a> !RefUnwindSafe for ListBuilder<'a>

§

impl<'a> !Send for ListBuilder<'a>

§

impl<'a> !Sync for ListBuilder<'a>

§

impl<'a> Unpin for ListBuilder<'a>

§

impl<'a> UnsafeUnpin for ListBuilder<'a>

§

impl<'a> !UnwindSafe for ListBuilder<'a>

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> SizeEq<Cell<T>> for T
where T: ?Sized,

Source§

type CastFrom = CastFromWrapper

Source§

impl<T> SizeEq<ManuallyDrop<T>> for T
where T: ?Sized,

Source§

type CastFrom = CastFromWrapper

Source§

impl<T> SizeEq<MaybeUninit<T>> for T

Source§

impl<T> SizeEq<ReadOnly<T>> for T
where T: ?Sized,

Source§

type CastFrom = CastFromReadOnly

Source§

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

Source§

impl<T> SizeEq<Unalign<T>> for T

Source§

type CastFrom = CastFromWrapper

Source§

impl<T> SizeEq<UnsafeCell<T>> for T
where T: ?Sized,

Source§

type CastFrom = CastFromWrapper

Source§

impl<T> SizeEq<Wrapping<T>> for T

Source§

type CastFrom = CastFromWrapper

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> InvariantsEq<ManuallyDrop<T>> for T
where T: ?Sized,

Source§

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

Source§

impl<T> InvariantsEq<Unalign<T>> for T

Source§

impl<T> InvariantsEq<Wrapping<T>> for T

Source§

impl<Src, Dst, A, SV, DV, R> MutationCompatible<Src, A, SV, DV, (BecauseRead, R)> for Dst
where A: Aliasing, SV: Validity, DV: Validity, Src: Read<A, R> + ?Sized, Dst: Read<A, R> + ?Sized,

Source§

impl<Src, Dst, A, SV, DV> MutationCompatible<Src, A, SV, DV, BecauseInvariantsEq> for Dst
where A: Aliasing, SV: Validity, DV: Validity, Src: TransmuteFrom<Dst, DV, SV> + ?Sized, Dst: TransmuteFrom<Src, SV, DV> + InvariantsEq<Src> + ?Sized,

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> TransmuteFrom<Cell<T>, Valid, Valid> for T
where T: ?Sized,

Source§

impl<T> TransmuteFrom<ManuallyDrop<T>, Valid, Valid> for T
where T: ?Sized,

Source§

impl<T> TransmuteFrom<ReadOnly<T>, Valid, Valid> for T
where T: ?Sized,

Source§

impl<Src, Dst> TransmuteFrom<Src, Initialized, Initialized> for Dst
where Src: ?Sized, Dst: ?Sized,

Source§

impl<Src, Dst, V> TransmuteFrom<Src, V, Uninit> for Dst
where V: Validity, Src: ?Sized, Dst: ?Sized,

Source§

impl<Src, Dst> TransmuteFrom<Src, Valid, Initialized> for Dst
where Src: IntoBytes + ?Sized, Dst: ?Sized,

Source§

impl<T> TransmuteFrom<Unalign<T>, Valid, Valid> for T

Source§

impl<T> TransmuteFrom<UnsafeCell<T>, Valid, Valid> for T
where T: ?Sized,

Source§

impl<T> TransmuteFrom<Wrapping<T>, Valid, Valid> for T

Source§

impl<Src, Dst, A, SV, DV, C, R> TransmuteFromPtr<Src, A, SV, DV, C, R> for Dst
where A: Aliasing, SV: Validity, DV: Validity, C: CastExact<Src, Dst>, Dst: TransmuteFrom<Src, SV, DV> + TryTransmuteFromPtr<Src, A, SV, DV, C, R> + ?Sized, Src: ?Sized,

Source§

impl<Src, Dst, SV, DV, A, C, R> TryTransmuteFromPtr<Src, A, SV, DV, C, (BecauseMutationCompatible, R)> for Dst
where A: Aliasing, SV: Validity, DV: Validity, Src: TransmuteFrom<Dst, DV, SV> + ?Sized, Dst: MutationCompatible<Src, A, SV, DV, R> + ?Sized, C: CastExact<Src, Dst>,

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: 16 bytes