[][src]Struct abistr::CStrPtr

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

CStrPtr is ABI compatible with *const c_char. null() is treated as an empty string.

If you want to treat null() as None, use Option<CStrNonNull> instead.

Implementations

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

pub const NULL: Self[src]

pub unsafe fn from_ptr_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 CStrPtr. 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 CStrPtr. 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, possibly null() C string.

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

Checks if self is null().

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<'_> AsOptCStr for CStrPtr<'_>[src]

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

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

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

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

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

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

Auto Trait Implementations

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

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

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

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

impl<'s> UnwindSafe for CStrPtr<'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.