[−][src]Struct abistr::CStrPtr
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 nullptr
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]
bytes: &'s [u8]
) -> Result<Self, FromBytesWithNulError>
Convert a raw slice of bytes into a CStrPtr
. bytes
should end with \0
, but contain no interior \0
s 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]
Trait Implementations
impl<'_> AsOptCStr for CStrPtr<'_>
[src]
pub fn as_opt_cstr(&self) -> *const c_char
[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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,