pub struct StrVec(SEXP);Expand description
Owned handle to an R character vector (STRSXP).
This wrapper provides safe methods for building character vectors element-by-element with proper GC protection.
Tuple Fields§
§0: SEXPImplementations§
Source§impl StrVec
impl StrVec
Sourcepub const unsafe fn from_raw(sexp: SEXP) -> Self
pub const unsafe fn from_raw(sexp: SEXP) -> Self
Wrap an existing STRSXP without additional checks.
§Safety
Caller must ensure sexp is a valid character vector (STRSXP)
whose lifetime remains managed by R.
Sourcepub fn get_charsxp(self, idx: isize) -> Option<SEXP>
pub fn get_charsxp(self, idx: isize) -> Option<SEXP>
Get the CHARSXP at the given index.
Returns None if out of bounds.
Sourcepub fn get_str(self, idx: isize) -> Option<&'static str>
pub fn get_str(self, idx: isize) -> Option<&'static str>
Get the string at the given index (zero-copy).
Returns None if out of bounds or if the element is NA_character_.
Panics if the CHARSXP is not valid UTF-8 (should not happen in a UTF-8 locale).
Sourcepub fn get_cow(self, idx: isize) -> Option<Cow<'static, str>>
pub fn get_cow(self, idx: isize) -> Option<Cow<'static, str>>
Get the string at the given index as Cow<str> (encoding-safe).
Returns Cow::Borrowed for UTF-8 strings (zero-copy), Cow::Owned for
non-UTF-8 strings (translated via Rf_translateCharUTF8).
Returns None if out of bounds or NA_character_.
Sourcepub fn iter(self) -> StrVecIter ⓘ
pub fn iter(self) -> StrVecIter ⓘ
Iterate over elements as Option<&str>.
NA_character_ elements yield None, valid strings yield Some(&str).
Zero-copy — each &str borrows directly from R’s CHARSXP.
Sourcepub fn iter_cow(self) -> StrVecCowIter ⓘ
pub fn iter_cow(self) -> StrVecCowIter ⓘ
Iterate over elements as Option<Cow<str>> (encoding-safe).
Like iter but handles non-UTF-8 CHARSXPs gracefully.
Sourcepub unsafe fn set_charsxp(self, idx: isize, charsxp: SEXP)
pub unsafe fn set_charsxp(self, idx: isize, charsxp: SEXP)
Set a CHARSXP at the given index, protecting it during insertion.
This is the safe way to insert a freshly allocated CHARSXP into a string vector.
§Safety
- Must be called from the R main thread
charsxpmust be a valid CHARSXP (fromRf_mkChar*orSTRING_ELT)selfmust be a valid, protected STRSXP
§Panics
Panics if idx is out of bounds.
Sourcepub unsafe fn set_charsxp_unchecked(self, idx: isize, charsxp: SEXP)
pub unsafe fn set_charsxp_unchecked(self, idx: isize, charsxp: SEXP)
Set a CHARSXP without protecting it.
§Safety
In addition to the safety requirements of set_charsxp:
- The caller must ensure
charsxpis already protected or from the global CHARSXP cache.
Trait Implementations§
Source§impl IntoIterator for StrVec
impl IntoIterator for StrVec
Source§impl IntoR for StrVec
impl IntoR for StrVec
Source§type Error = Infallible
type Error = Infallible
Source§fn try_into_sexp(self) -> Result<SEXP, Self::Error>
fn try_into_sexp(self) -> Result<SEXP, Self::Error>
Source§impl TryFromSexp for StrVec
impl TryFromSexp for StrVec
impl Copy for StrVec
impl TrivialClone for StrVec
Auto Trait Implementations§
impl Freeze for StrVec
impl RefUnwindSafe for StrVec
impl Send for StrVec
impl Sync for StrVec
impl Unpin for StrVec
impl UnsafeUnpin for StrVec
impl UnwindSafe for StrVec
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> SizeEq<MaybeUninit<T>> for T
impl<T> SizeEq<MaybeUninit<T>> for T
type CastFrom = CastSizedExact
Source§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 moreimpl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> InvariantsEq<ManuallyDrop<T>> for Twhere
T: ?Sized,
impl<T> InvariantsEq<T> for Twhere
T: ?Sized,
impl<T> InvariantsEq<Unalign<T>> for T
impl<T> InvariantsEq<Wrapping<T>> for T
impl<Src, Dst, A, SV, DV, R> MutationCompatible<Src, A, SV, DV, (BecauseRead, R)> for Dst
impl<Src, Dst, A, SV, DV> MutationCompatible<Src, A, SV, DV, BecauseInvariantsEq> for Dstwhere
A: Aliasing,
SV: Validity,
DV: Validity,
Src: TransmuteFrom<Dst, DV, SV> + ?Sized,
Dst: TransmuteFrom<Src, SV, DV> + InvariantsEq<Src> + ?Sized,
impl<T> Printable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
impl<T> TransmuteFrom<Cell<T>, Valid, Valid> for Twhere
T: ?Sized,
impl<T> TransmuteFrom<ManuallyDrop<T>, Valid, Valid> for Twhere
T: ?Sized,
impl<T> TransmuteFrom<ReadOnly<T>, Valid, Valid> for Twhere
T: ?Sized,
impl<Src, Dst> TransmuteFrom<Src, Initialized, Initialized> for Dst
impl<Src, Dst, V> TransmuteFrom<Src, V, Uninit> for Dst
impl<Src, Dst> TransmuteFrom<Src, Valid, Initialized> for Dst
impl<T> TransmuteFrom<Unalign<T>, Valid, Valid> for T
impl<T> TransmuteFrom<UnsafeCell<T>, Valid, Valid> for Twhere
T: ?Sized,
impl<T> TransmuteFrom<Wrapping<T>, Valid, Valid> for T
impl<Src, Dst, A, SV, DV, C, R> TransmuteFromPtr<Src, A, SV, DV, C, R> for Dstwhere
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,
impl<Src, Dst, SV, DV, A, C, R> TryTransmuteFromPtr<Src, A, SV, DV, C, (BecauseMutationCompatible, R)> for Dstwhere
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: 8 bytes