pub struct NulStr<'a, T: Kind> { /* private fields */ }Expand description
Safe wrapper for immutable borrowed C strings, guaranteed to be the same layout as *const u8.
Implementations§
Source§impl<'a, T: Kind> NulStr<'a, T>
impl<'a, T: Kind> NulStr<'a, T>
Sourcepub const unsafe fn from_ptr(ptr: *const T::C) -> Self
pub const unsafe fn from_ptr(ptr: *const T::C) -> Self
Safety
The ptr must be valid up to and including the first NUL byte from the base ptr.
pub unsafe fn from_nullable_ptr(ptr: *const T::C) -> Option<Self>
Sourcepub fn find_get_subslice_or_all(
self,
c: impl Into<T::Char>,
) -> Result<(&'a [T::Char], Self), (&'a [T::Char], Self)>
pub fn find_get_subslice_or_all( self, c: impl Into<T::Char>, ) -> Result<(&'a [T::Char], Self), (&'a [T::Char], Self)>
Look for the closest occurence of c, and if found, split the string into a slice up to
that byte and a CStr starting at that byte.
Sourcepub unsafe fn slice_until_substr(self, substr: NulStr<'_, T>) -> &'a [T::Char]
pub unsafe fn slice_until_substr(self, substr: NulStr<'_, T>) -> &'a [T::Char]
§Safety
substr must be contained within self
Sourcepub fn find_get_subslice(self, c: T::Char) -> Option<(&'a [T::Char], Self)>
pub fn find_get_subslice(self, c: T::Char) -> Option<(&'a [T::Char], Self)>
Look for the closest occurence of c, and if found, split the string into a slice up to
that byte and a CStr starting at that byte.
Sourcepub fn find(self, c: T::Char) -> Option<Self>
pub fn find(self, c: T::Char) -> Option<Self>
Look for the closest occurence of c, and return a new string starting at that byte if
found.
pub fn contains(self, c: T::Char) -> bool
pub fn first(self) -> T::Char
pub fn first_char(self) -> Option<char>
Sourcepub fn split_first_char(self) -> Option<(char, Self)>
pub fn split_first_char(self) -> Option<(char, Self)>
Same as split_first except also requires that the first char be convertible into char
Sourcepub fn split_first(self) -> Option<(T::Char, Self)>
pub fn split_first(self) -> Option<(T::Char, Self)>
Split this string into Some((first_byte, string_after_that)) or None if empty.
pub fn to_chars_with_nul(self) -> &'a [T::Char]
pub fn to_chars(self) -> &'a [T::Char]
pub const fn as_ptr(self) -> *const T::C
pub const unsafe fn from_chars_with_nul_unchecked(chars: &'a [T::Char]) -> Self
pub fn from_chars_with_nul( chars: &'a [T::Char], ) -> Result<Self, FromCharsWithNulError>
pub fn from_chars_until_nul( chars: &'a [T::Char], ) -> Result<Self, FromCharsUntilNulError>
pub fn is_empty(&self) -> bool
Source§impl<'a> NulStr<'a, Thin>
impl<'a> NulStr<'a, Thin>
pub fn to_owned_cstring(self) -> CString
pub fn borrow(string: &'a CString) -> Self
pub fn to_bytes(self) -> &'a [u8]
pub fn to_bytes_with_nul(self) -> &'a [u8]
pub fn to_str(self) -> Result<&'a str, Utf8Error>
pub fn to_string_lossy(self) -> Cow<'a, str>
pub const unsafe fn from_bytes_with_nul_unchecked(bytes: &'a [u8]) -> Self
pub fn from_bytes_with_nul( bytes: &'a [u8], ) -> Result<Self, FromCharsWithNulError>
pub fn from_bytes_until_nul( bytes: &'a [u8], ) -> Result<Self, FromCharsUntilNulError>
Trait Implementations§
impl<'a, T: Copy + Kind> Copy for NulStr<'a, T>
impl<T: Kind> Send for NulStr<'_, T>
impl<T: Kind> Sync for NulStr<'_, T>
Auto Trait Implementations§
impl<'a, T> Freeze for NulStr<'a, T>
impl<'a, T> RefUnwindSafe for NulStr<'a, T>
impl<'a, T> Unpin for NulStr<'a, T>
impl<'a, T> UnsafeUnpin for NulStr<'a, T>
impl<'a, T> UnwindSafe for NulStr<'a, T>
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