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

Convert to a StrVec wrapper.

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> Freeze for StrVecBuilder<'a>

§

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

§

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

§

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

§

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

§

impl<'a> UnsafeUnpin for StrVecBuilder<'a>

§

impl<'a> !UnwindSafe 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, 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.