[][src]Struct abistr::CStrNonNull

#[repr(transparent)]pub struct CStrNonNull<'s> { /* fields omitted */ }

Option<CStrNonNull> is ABI compatible with *const c_char.

If you want to treat null() as "", use CStrPtr instead.

Implementations

impl<'s> CStrNonNull<'s>[src]

pub unsafe fn from_ptr_unchecked_unbounded(ptr: *const c_char) -> Self[src]

Convert a raw C-string into a CStrPtr. Note that the lifetime of the returned reference is unbounded!

Safety

  • ptr cannot be null
  • ptr must point to a \0-terminated C string
  • The underlying C-string cannot change for the duration of the lifetime 's.
  • The lifetime 's is unbounded by this fn. Very easy to accidentally extend. Be careful!

pub fn from_bytes_with_nul(
    bytes: &'s [u8]
) -> Result<Self, FromBytesWithNulError>
[src]

Convert a raw slice of bytes into a CStrNonNull. bytes should end with \0, but contain no interior \0s otherwise.

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

Convert a raw slice of bytes to a CStrNonNull. The resulting string will be terminated at the first \0 in bytes.

Safety

  • bytes must contain at least one \0.

pub fn as_ptr(&self) -> *const c_char[src]

Treat self as a raw C string.

pub fn as_non_null(&self) -> NonNull<c_char>[src]

Treat self as a NonNull C string.

pub fn is_empty(&self) -> bool[src]

Checks if self is empty (either null(), or the first character is \0.)

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

Convert self to a &[u8] slice, excluding the terminal \0.

O(n) to find the terminal \0.

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

Convert self to a &[u8] slice, including the terminal \0.

O(n) to find the terminal \0.

pub fn to_cstr(&self) -> &'s CStr[src]

Convert self to a std::ffi::CStr.

O(n) to find the terminal \0.

pub fn to_str(&self) -> Result<&'s str, Utf8Error>[src]

Convert self to a &str.

O(n) to find the terminal \0 and validate UTF8.

pub fn to_string_lossy(&self) -> Cow<'s, str>[src]

Convert self to a Cow<str>.

O(n) to find the terminal \0 and validate, and to convert UTF8ish data to UTF8 if necesssary.

Trait Implementations

impl<'_> AsCStr for CStrNonNull<'_>[src]

impl<'s> Clone for CStrNonNull<'s>[src]

impl<'s> Copy for CStrNonNull<'s>[src]

impl<'_> Debug for CStrNonNull<'_>[src]

impl<'_> Default for CStrNonNull<'_>[src]

impl<'s> From<&'s CStr> for CStrNonNull<'s>[src]

impl<'s> From<CStrNonNull<'s>> for &'s CStr[src]

Auto Trait Implementations

impl<'s> RefUnwindSafe for CStrNonNull<'s>[src]

impl<'s> !Send for CStrNonNull<'s>[src]

impl<'s> !Sync for CStrNonNull<'s>[src]

impl<'s> Unpin for CStrNonNull<'s>[src]

impl<'s> UnwindSafe for CStrNonNull<'s>[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.