pub struct OwnedCStrs { /* private fields */ }Expand description
A AsCStrArray backed by a collection of owned strings
This struct is a counterpart to BorrowedCStrs that owns the strings
themselves instead of borrowing them. OwnedCStrs owns both the allocation
for the array of pointers and the Vec of owned strings, ensuring that the
pointers remain valid for the lifetime of the OwnedCStrs.
The implementation of FromIterator allows you to create an OwnedCStrs
from an iterator of CStrings, which can be useful when you want to create
an AsCStrArray from scratch and need to own the strings themselves.
Implementations§
Source§impl OwnedCStrs
impl OwnedCStrs
Sourcepub fn new(values: Vec<CString>) -> Self
pub fn new(values: Vec<CString>) -> Self
Creates a new OwnedCStrs from a Vec<CString>.
The given values is stored in the OwnedCStrs for the lifetime of it
to keep the strings valid and unmodified. A null-terminated array of
pointers to the C-style strings is created from the values and stored
in the OwnedCStrs as well. The pointer to the array is returned by the
as_ptr method.
Sourcepub unsafe fn from_pointers_and_values(
pointers: Vec<*const c_char>,
values: Vec<CString>,
) -> Self
pub unsafe fn from_pointers_and_values( pointers: Vec<*const c_char>, values: Vec<CString>, ) -> Self
Creates a new OwnedCStrs from its inner components.
This function directly uses the given pointers as the content of the
OwnedCStrs. The pointers is a null-terminated array of pointers to
C-style strings that is returned by the as_ptr method.
The values is a Vec<CString> stored in the OwnedCStrs for the
lifetime of it.
§Safety
The caller must ensure that the pointers in the first Vec point to
valid C-style strings, and that the Vec is null-terminated (i.e., the
last pointer is a null pointer). The strings must remain valid and
unmodified for the lifetime of the OwnedCStrs.
This function does not require that the pointers point to strings
contained in values. However, if the strings pointed to by pointers
are modified or dropped through other means while the OwnedCStrs is
alive, it may lead to undefined behavior when the pointers are used. If
the strings pointed to by pointers are not contained in values, you
should consider using BorrowedCStrs instead, as it supports
lifetime-based safety guarantees for the strings.
Sourcepub fn into_pointers_and_values(self) -> (Vec<*const c_char>, Vec<CString>)
pub fn into_pointers_and_values(self) -> (Vec<*const c_char>, Vec<CString>)
Consumes the OwnedCStrs and returns the owned array of pointers and values.
This function just returns its inner components. The caller is
responsible for ensuring the validity of the returned pointers if they
intend to use them. If self was created by OwnedCStrs::new, the
C-style strings pointed to by the returned pointers will be valid until
the returned values are mutated or dropped.
Trait Implementations§
Source§impl AsCStrArray for OwnedCStrs
impl AsCStrArray for OwnedCStrs
Source§impl Clone for OwnedCStrs
Clones an OwnedCStrs by cloning its owned strings and reconstructing the
pointer array to point to the new strings.
impl Clone for OwnedCStrs
Clones an OwnedCStrs by cloning its owned strings and reconstructing the
pointer array to point to the new strings.
Source§impl Debug for OwnedCStrs
impl Debug for OwnedCStrs
Source§impl From<Vec<CString>> for OwnedCStrs
Converts a Vec<CString> into an OwnedCStrs. (See OwnedCStrs::new.)
impl From<Vec<CString>> for OwnedCStrs
Converts a Vec<CString> into an OwnedCStrs. (See OwnedCStrs::new.)
Source§impl<A> FromIterator<A> for OwnedCStrs
Creates an OwnedCStrs from an iterator of values that can be converted into CStrings.
impl<A> FromIterator<A> for OwnedCStrs
Creates an OwnedCStrs from an iterator of values that can be converted into CStrings.
Source§fn from_iter<I: IntoIterator<Item = A>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = A>>(iter: I) -> Self
Auto Trait Implementations§
impl !Send for OwnedCStrs
impl !Sync for OwnedCStrs
impl Freeze for OwnedCStrs
impl RefUnwindSafe for OwnedCStrs
impl Unpin for OwnedCStrs
impl UnsafeUnpin for OwnedCStrs
impl UnwindSafe for OwnedCStrs
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> IntoCStrArray for Twhere
T: AsCStrArray,
impl<T> IntoCStrArray for Twhere
T: AsCStrArray,
Source§type CStrArray = T
type CStrArray = T
self can be converted into, which must implement AsCStrArray.Source§fn into_c_str_array(self) -> <T as IntoCStrArray>::CStrArray
fn into_c_str_array(self) -> <T as IntoCStrArray>::CStrArray
self into a type that implements AsCStrArray.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more