pub struct StrVec<'a>(SEXP, PhantomData<&'a str>);Expand description
Borrowed view over an R character vector (STRSXP).
The 'a lifetime leashes every &str this view hands out to the window in
which the underlying STRSXP stays GC-reachable. At a #[miniextendr]
boundary, write StrVec<'_>: R protects .Call arguments for the call’s
duration, so the elided lifetime is bounded by the call and the borrows
cannot escape into an ExternalPtr, a global, or another thread — doing so
is a compile error (the &str would have to outlive 'a). Callers that own
the rooting obligation reach for the unsafe *_static family instead.
Copy and cheap (a single SEXP); covariant in 'a.
Tuple Fields§
§0: SEXP§1: PhantomData<&'a str>Implementations§
Source§impl<'a> StrVec<'a>
impl<'a> StrVec<'a>
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)
that stays GC-reachable for the inferred lifetime 'a.
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<&'a str>
pub fn get_str(self, idx: isize) -> Option<&'a str>
Get the string at the given index (zero-copy), leashed to 'a.
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<'a, str>>
pub fn get_cow(self, idx: isize) -> Option<Cow<'a, str>>
Get the string at the given index as Cow<str> (encoding-safe), leashed to 'a.
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 unsafe fn get_str_static(self, idx: isize) -> Option<&'static str>
pub unsafe fn get_str_static(self, idx: isize) -> Option<&'static str>
Get the string at the given index as &'static str — the courageous escape.
Unlike get_str, the returned reference is not leashed
to 'a, so it can be stored in an ExternalPtr, a global, or sent across
threads. The string data lives in R’s CHARSXP; it is only valid while that
STRSXP stays GC-reachable.
§Safety
The caller takes on the rooting obligation: the underlying STRSXP must be
kept reachable by R (e.g. via the prot slot of the ExternalPtr it is
stored in, or R_PreserveObject) for as long as the returned &'static str
is used. Letting R GC the source is use-after-free.
Sourcepub unsafe fn get_cow_static(self, idx: isize) -> Option<Cow<'static, str>>
pub unsafe fn get_cow_static(self, idx: isize) -> Option<Cow<'static, str>>
Get the string at the given index as Cow<'static, str> — the courageous escape.
Cow analogue of get_str_static; same rooting
obligation for the borrowed (Cow::Borrowed) case.
§Safety
See get_str_static.
Sourcepub fn iter(self) -> StrVecIter<'a> ⓘ
pub fn iter(self) -> StrVecIter<'a> ⓘ
Iterate over elements as Option<&str> (leashed to 'a).
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<'a> ⓘ
pub fn iter_cow(self) -> StrVecCowIter<'a> ⓘ
Iterate over elements as Option<Cow<str>> (encoding-safe, leashed to 'a).
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§
impl<'a> Copy for StrVec<'a>
Source§impl<'a> IntoIterator for StrVec<'a>
impl<'a> IntoIterator for StrVec<'a>
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>
impl<'a> TrivialClone for StrVec<'a>
Auto Trait Implementations§
impl<'a> Freeze for StrVec<'a>
impl<'a> RefUnwindSafe for StrVec<'a>
impl<'a> Send for StrVec<'a>
impl<'a> Sync for StrVec<'a>
impl<'a> Unpin for StrVec<'a>
impl<'a> UnsafeUnpin for StrVec<'a>
impl<'a> UnwindSafe for StrVec<'a>
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,
impl<T> Printable for T
Source§impl<T> SizeHint for Twhere
T: ?Sized,
impl<T> SizeHint for Twhere
T: ?Sized,
Source§default fn lower_bound(&self) -> usize
default fn lower_bound(&self) -> usize
core_io_internals)[u8; 12] could return any value between 0 and
12 inclusively as a correct implementation. Read moreSource§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 moreLayout§
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