[−][src]Struct pelite::util::CStr
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]
const MIN_SIZE_OF: usize
[src]
const ALIGN_OF: usize
[src]
unsafe fn from_bytes(bytes: &[u8]) -> Option<&CStr>
[src]
impl AsRef<[u8]> for CStr
[src]
impl Eq for CStr
[src]
impl<T: AsRef<[u8]> + ?Sized> PartialOrd<T> for CStr
[src]
fn partial_cmp(&self, rhs: &T) -> Option<Ordering>
[src]
#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl<T: AsRef<[u8]> + ?Sized> PartialEq<T> for CStr
[src]
impl Ord for CStr
[src]
fn cmp(&self, other: &CStr) -> Ordering
[src]
fn max(self, other: Self) -> Self
1.21.0[src]
fn min(self, other: Self) -> Self
1.21.0[src]
fn clamp(self, min: Self, max: Self) -> Self
[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,