[][src]Struct pelite::util::CStr

pub struct CStr { /* fields omitted */ }

Nul-terminated C string.

Methods

impl CStr[src]

pub fn empty() -> &'static CStr[src]

Returns the empty nul-terminated C string.

pub fn from_bytes(bytes: &[u8]) -> Option<&CStr>[src]

Scans the byte slice for a nul-terminated C string.

Returns None if no nul byte was found.

Examples

use pelite::util::CStr;

let c_str = CStr::from_bytes(b"Hello\0World\0").unwrap();
assert_eq!(c_str.to_str(), Ok("Hello"));
assert_eq!(c_str.c_str(), b"Hello\0");
assert_eq!(c_str.len(), 5);

let no_nul = CStr::from_bytes(b"not nul terminated");
assert_eq!(no_nul, None);

pub unsafe fn from_bytes_unchecked(bytes: &[u8]) -> &CStr[src]

Interprets a byte slice as a C string.

Safety

Ensure that the byte slice ends with the only nul byte.

pub fn c_str(&self) -> &[u8][src]

Gets the C string as a nul terminated byte slice.

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

Casts the C string to an UTF8 validated str.

Trait Implementations

impl FromBytes for CStr[src]

impl AsRef<[u8]> for CStr[src]

impl Eq for CStr[src]

impl<T: AsRef<[u8]> + ?Sized> PartialOrd<T> for CStr[src]

impl<T: AsRef<[u8]> + ?Sized> PartialEq<T> for CStr[src]

impl Ord for CStr[src]

impl Hash for CStr[src]

impl Deref for CStr[src]

type Target = [u8]

The resulting type after dereferencing.

impl Debug for CStr[src]

impl Display for CStr[src]

impl Serialize for CStr[src]

Auto Trait Implementations

impl Sync for CStr

impl Send for CStr

impl Unpin for CStr

impl UnwindSafe for CStr

impl RefUnwindSafe for CStr

Blanket Implementations

impl<T> ToString for T where
    T: Display + ?Sized
[src]

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

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

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