pub struct StrVec<'a>(SEXP, Option<&'a ChildRoots>);Expand description
Borrowed view over an R character vector (STRSXP).
Strings returned by the view carry 'a. Constructors must tie that lifetime
to a root that keeps the source reachable. ProtectedStrVec::as_strvec
does so through a borrow of its owner.
try_from_root borrows a lifetime-carrying root.
Generated wrappers use this path for StrVec<'_> parameters. Raw
TryFromSexp is unavailable: a copyable SEXP cannot constrain the view’s
lifetime. Use ProtectedStrVec when the result must own its root.
Copy and cheap (a SEXP and a retention reference); covariant in 'a.
Uncached ALTREP elements read through a rooted view stay alive for 'a.
Tuple Fields§
§0: SEXP§1: Option<&'a ChildRoots>Implementations§
Source§impl<'a> StrVec<'a>
impl<'a> StrVec<'a>
Source#[doc(hidden)]pub const NATIVE_BORROW: Option<NativeBorrow> = None
#[doc(hidden)]pub const NATIVE_BORROW: Option<NativeBorrow> = None
Strings do not retain a pointer to a native numeric vector.
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. An ALTREP class
must also retain every CHARSXP read through this raw view for 'a;
otherwise use try_from_root or ProtectedStrVec.
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; the CHARSXP must remain
reachable. For an uncached ALTREP element, retain this view’s protection
scope or ProtectedStrVec owner as well as the source vector.
§Safety
The caller must keep the returned CHARSXP reachable for as long as the reference is used. Rooting an ordinary source STRSXP suffices; an ALTREP source may need this view’s scope/owner or a separate root for the child. Letting R collect that child 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.
Source§impl<'a> StrVec<'a>
impl<'a> StrVec<'a>
Sourcepub fn try_from_root(root: Root<'a>) -> Result<Self, SexpError>
pub fn try_from_root(root: Root<'a>) -> Result<Self, SexpError>
Borrow a character vector for the lifetime of its root.
The result cannot acquire a lifetime longer than the supplied root.
Raw TryFromSexp is intentionally unavailable for this borrowed view.
use miniextendr_api::{Root, StrVec};
fn escape<'a>(root: Root<'a>) -> StrVec<'static> {
StrVec::try_from_root(root).unwrap()
}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<'_>
impl<'a> TrivialClone for StrVec<'a>
Source§impl<'a> TryFromRoot<'a> for StrVec<'a>
impl<'a> TryFromRoot<'a> for StrVec<'a>
Source§fn try_from_root(root: Root<'a>) -> Result<Self, Self::Error>
fn try_from_root(root: Root<'a>) -> Result<Self, Self::Error>
root.Source§#[doc(hidden)]const NATIVE_BORROW: Option<NativeBorrow> = None
#[doc(hidden)]const NATIVE_BORROW: Option<NativeBorrow> = None
Auto Trait Implementations§
impl<'a> !RefUnwindSafe for StrVec<'a>
impl<'a> !Send for StrVec<'a>
impl<'a> !Sync for StrVec<'a>
impl<'a> !UnwindSafe for StrVec<'a>
impl<'a> Freeze for StrVec<'a>
impl<'a> Unpin for StrVec<'a>
impl<'a> UnsafeUnpin 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> ConsumingFallible for Twhere
T: Clone,
impl<T> Printable for T
Source§impl<T> RCopy for Twhere
T: Copy,
impl<T> RCopy for Twhere
T: Copy,
Source§impl<T> RDebug for Twhere
T: Debug,
impl<T> RDebug for Twhere
T: Debug,
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: 16 bytes