Skip to main content

StrVecBuilder

Struct StrVecBuilder 

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

Builder for constructing string vectors with efficient protection management.

§Example

unsafe fn build_strvec(strings: &[&str]) -> SEXP {
    let scope = ProtectScope::new();
    let builder = StrVecBuilder::new(&scope, strings.len() as isize);

    for (i, s) in strings.iter().enumerate() {
        builder.set_str(i as isize, s);
    }

    builder.into_sexp()
}

Fields§

§vec: SEXP§_scope: &'a ProtectScope

Implementations§

Source§

impl<'a> StrVecBuilder<'a>

Source

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

Create a new string vector builder with the given length.

§Safety

Must be called from the R main thread.

Source

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

Create a new string vector builder via the unchecked FFI allocation path.

_unchecked twin of new: the STRSXP is allocated with Rf_allocVector_unchecked (see ProtectScope::alloc_character_unchecked), bypassing the main-thread assertion. Use inside ALTREP callbacks, with_r_unwind_protect, or with_r_thread bodies, and pair element insertion with the _unchecked string-element setters.

§Safety

Must be called from the R main thread, in a context where the checked-FFI assertion is intentionally bypassed (see CLAUDE.md “FFI thread checking”).

Source

pub unsafe fn set_str(&self, idx: isize, s: &str)

Set an element from a Rust string.

§Safety

Must be called from the R main thread.

Source

pub unsafe fn set_na(&self, idx: isize)

Set an element to NA_character_.

§Safety

Must be called from the R main thread.

Source

pub unsafe fn set_opt_str(&self, idx: isize, s: Option<&str>)

Set an element from an optional string.

§Safety

Must be called from the R main thread.

Source

pub fn as_sexp(&self) -> SEXP

Get the underlying SEXP.

Source

pub fn into_strvec(self) -> StrVec<'a>

Convert to a StrVec view, leashed to the builder’s protect scope 'a.

Source

pub fn into_sexp(self) -> SEXP

Convert to the underlying SEXP.

Source

pub fn len(&self) -> isize

Get the length.

Source

pub fn is_empty(&self) -> bool

Check if empty.

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

impl<'a> Freeze for StrVecBuilder<'a>

§

impl<'a> Unpin for StrVecBuilder<'a>

§

impl<'a> UnsafeUnpin for StrVecBuilder<'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> 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 = 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.

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