Skip to main content

NulStr

Struct NulStr 

Source
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>

Source

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.

Source

pub unsafe fn from_nullable_ptr(ptr: *const T::C) -> Option<Self>

Source

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.

Source

pub unsafe fn slice_until_substr(self, substr: NulStr<'_, T>) -> &'a [T::Char]

§Safety

substr must be contained within self

Source

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.

Source

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.

Source

pub fn contains(self, c: T::Char) -> bool

Source

pub fn first(self) -> T::Char

Source

pub fn first_char(self) -> Option<char>

Source

pub fn split_first_char(self) -> Option<(char, Self)>

Same as split_first except also requires that the first char be convertible into char

Source

pub fn split_first(self) -> Option<(T::Char, Self)>

Split this string into Some((first_byte, string_after_that)) or None if empty.

Source

pub fn to_chars_with_nul(self) -> &'a [T::Char]

Source

pub fn to_chars(self) -> &'a [T::Char]

Source

pub const fn as_ptr(self) -> *const T::C

Source

pub const unsafe fn from_chars_with_nul_unchecked(chars: &'a [T::Char]) -> Self

Source

pub fn from_chars_with_nul( chars: &'a [T::Char], ) -> Result<Self, FromCharsWithNulError>

Source

pub fn from_chars_until_nul( chars: &'a [T::Char], ) -> Result<Self, FromCharsUntilNulError>

Source

pub fn len(self) -> usize

Scan the string to get its length.

Source

pub fn is_empty(&self) -> bool

Source§

impl<'a> NulStr<'a, Thin>

Source

pub fn to_owned_cstring(self) -> CString

Source

pub fn borrow(string: &'a CString) -> Self

Source

pub fn to_bytes(self) -> &'a [u8]

Source

pub fn to_bytes_with_nul(self) -> &'a [u8]

Source

pub fn to_str(self) -> Result<&'a str, Utf8Error>

Source

pub fn to_string_lossy(self) -> Cow<'a, str>

Source

pub const unsafe fn from_bytes_with_nul_unchecked(bytes: &'a [u8]) -> Self

Source

pub fn from_bytes_with_nul( bytes: &'a [u8], ) -> Result<Self, FromCharsWithNulError>

Source

pub fn from_bytes_until_nul( bytes: &'a [u8], ) -> Result<Self, FromCharsUntilNulError>

Trait Implementations§

Source§

impl<'a, T: Clone + Kind> Clone for NulStr<'a, T>
where T::C: Clone,

Source§

fn clone(&self) -> NulStr<'a, T>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> From<NulStr<'a, Thin>> for BufferReader<'a, Thin>

Source§

fn from(buff: CStr<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<NulStr<'a, Thin>> for Reader<'a, Thin>

Source§

fn from(buff: CStr<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<NulStr<'a, Wide>> for BufferReader<'a, Wide>

Source§

fn from(buff: WStr<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<NulStr<'a, Wide>> for Reader<'a, Wide>

Source§

fn from(buff: WStr<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a, T: Copy + Kind> Copy for NulStr<'a, T>
where T::C: Copy,

Source§

impl<T: Kind> Send for NulStr<'_, T>

Source§

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>
where <T as Kind>::C: RefUnwindSafe,

§

impl<'a, T> Unpin for NulStr<'a, T>

§

impl<'a, T> UnsafeUnpin for NulStr<'a, T>

§

impl<'a, T> UnwindSafe for NulStr<'a, T>
where <T as Kind>::C: RefUnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CastSlice<'_, T> for T

§

fn cast_slice(selves: &[T]) -> &[T]

§

impl<T> CastSliceMut<'_, T> for T

§

fn cast_slice_mut(selves: &mut [T]) -> &mut [T]

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.