Struct uefi::data_types::CStr8
source · pub struct CStr8(/* private fields */);
Expand description
A null-terminated Latin-1 string.
This type is largely inspired by core::ffi::CStr
with the exception that all characters are
guaranteed to be 8 bit long.
A CStr8
can be constructed from a core::ffi::CStr
via a try_from
call:
let cstr8: &CStr8 = TryFrom::try_from(cstr).unwrap();
For convenience, a CStr8
is comparable with core::str
and
alloc::string::String
from the standard library through the trait EqStrUntilNul
.
Implementations§
source§impl CStr8
impl CStr8
sourcepub unsafe fn from_ptr<'ptr>(ptr: *const Char8) -> &'ptr Self
pub unsafe fn from_ptr<'ptr>(ptr: *const Char8) -> &'ptr Self
Takes a raw pointer to a null-terminated Latin-1 string and wraps it in a CStr8 reference.
Safety
The function will start accessing memory from ptr
until the first
null byte. It’s the callers responsibility to ensure ptr
points to
a valid null-terminated string in accessible memory.
sourcepub fn from_bytes_with_nul(chars: &[u8]) -> Result<&Self, FromSliceWithNulError>
pub fn from_bytes_with_nul(chars: &[u8]) -> Result<&Self, FromSliceWithNulError>
Creates a CStr8 reference from bytes.
sourcepub const unsafe fn from_bytes_with_nul_unchecked(chars: &[u8]) -> &Self
pub const unsafe fn from_bytes_with_nul_unchecked(chars: &[u8]) -> &Self
Unsafely creates a CStr8 reference from bytes.
Safety
It’s the callers responsibility to ensure chars is a valid Latin-1 null-terminated string, with no interior null bytes.
Trait Implementations§
source§impl PartialEq for CStr8
impl PartialEq for CStr8
source§impl PartialOrd for CStr8
impl PartialOrd for CStr8
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more