pub struct CStrNonNull<'s> { /* private fields */ }Expand description
Option<CStrNonNull> is ABI compatible with *const c_char.
Implementations§
Source§impl<'s> CStrNonNull<'s>
impl<'s> CStrNonNull<'s>
Sourcepub unsafe fn from_ptr_unchecked_unbounded(ptr: *const c_char) -> Self
pub unsafe fn from_ptr_unchecked_unbounded(ptr: *const c_char) -> Self
Convert a raw C-string into a CStrPtr. Note that the lifetime of the returned reference is unbounded!
§Safety
ptrcannot be nullptrmust point to a\0-terminated C string- The underlying C-string cannot change for the duration of the lifetime
's. - The lifetime
'sis unbounded by this fn. Very easy to accidentally extend. Be careful!
Sourcepub fn from_bytes_with_nul(
bytes: &'s [u8],
) -> Result<Self, FromBytesWithNulError>
pub fn from_bytes_with_nul( bytes: &'s [u8], ) -> Result<Self, FromBytesWithNulError>
Convert a raw slice of bytes into a CStrNonNull. bytes should end with \0, but contain no interior \0s otherwise.
Sourcepub unsafe fn from_bytes_with_nul_unchecked(bytes: &'s [u8]) -> Self
pub unsafe fn from_bytes_with_nul_unchecked(bytes: &'s [u8]) -> Self
Convert a raw slice of bytes to a CStrNonNull. The resulting string will be terminated at the first \0 in bytes.
§Safety
bytesmust contain at least one\0.
Sourcepub fn as_non_null(&self) -> NonNull<c_char>
pub fn as_non_null(&self) -> NonNull<c_char>
Treat self as a NonNull C string.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Checks if self is empty (either null(), or the first character is \0.)
Sourcepub fn to_bytes(&self) -> &'s [u8] ⓘ
pub fn to_bytes(&self) -> &'s [u8] ⓘ
Convert self to a &[u8] slice, excluding the terminal \0.
O(n) to find the terminal \0.
Sourcepub fn to_bytes_with_nul(&self) -> &'s [u8] ⓘ
pub fn to_bytes_with_nul(&self) -> &'s [u8] ⓘ
Convert self to a &[u8] slice, including the terminal \0.
O(n) to find the terminal \0.
Sourcepub fn to_cstr(&self) -> &'s CStr
pub fn to_cstr(&self) -> &'s CStr
Convert self to a std::ffi::CStr.
O(n) to find the terminal \0.
Trait Implementations§
Source§impl AsCStr for CStrNonNull<'_>
impl AsCStr for CStrNonNull<'_>
Source§impl<'s> Clone for CStrNonNull<'s>
impl<'s> Clone for CStrNonNull<'s>
Source§fn clone(&self) -> CStrNonNull<'s>
fn clone(&self) -> CStrNonNull<'s>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl<'s> Copy for CStrNonNull<'s>
Source§impl Debug for CStrNonNull<'_>
impl Debug for CStrNonNull<'_>
Source§impl Default for CStrNonNull<'_>
impl Default for CStrNonNull<'_>
Source§impl<'s> From<&'s CStr> for CStrNonNull<'s>
impl<'s> From<&'s CStr> for CStrNonNull<'s>
Source§impl<'s> From<CStrNonNull<'s>> for &'s CStr
impl<'s> From<CStrNonNull<'s>> for &'s CStr
Source§fn from(s: CStrNonNull<'s>) -> Self
fn from(s: CStrNonNull<'s>) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl<'s> !Send for CStrNonNull<'s>
impl<'s> !Sync for CStrNonNull<'s>
impl<'s> Freeze for CStrNonNull<'s>
impl<'s> RefUnwindSafe for CStrNonNull<'s>
impl<'s> Unpin for CStrNonNull<'s>
impl<'s> UnsafeUnpin for CStrNonNull<'s>
impl<'s> UnwindSafe for CStrNonNull<'s>
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
Mutably borrows from an owned value. Read more