[−][src]Struct pelite::util::CStr
Nul-terminated C string.
Implementations
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 AsRef<[u8]> for CStr
[src]
impl Debug for CStr
[src]
impl Deref for CStr
[src]
impl Display for CStr
[src]
impl Eq for CStr
[src]
impl FromBytes for CStr
[src]
const MIN_SIZE_OF: usize
[src]
const ALIGN_OF: usize
[src]
unsafe fn from_bytes(bytes: &[u8]) -> Option<&CStr>
[src]
impl Hash for CStr
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,