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

source

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.

source

pub fn from_bytes_with_nul(chars: &[u8]) -> Result<&Self, FromSliceWithNulError>

Creates a CStr8 reference from bytes.

source

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.

source

pub const fn as_ptr(&self) -> *const Char8

Returns the inner pointer to this CStr8.

source

pub const fn as_bytes(&self) -> &[u8]

Returns the underlying bytes as slice including the terminating null character.

Trait Implementations§

source§

impl AsRef<[u8]> for CStr8

source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Borrow<[u8]> for CStr8

source§

fn borrow(&self) -> &[u8]

Immutably borrows from an owned value. Read more
source§

impl Debug for CStr8

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Display for CStr8

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<StrType: AsRef<str> + ?Sized> EqStrUntilNul<StrType> for CStr8

source§

fn eq_str_until_nul(&self, other: &StrType) -> bool

Checks if the provided Rust string StrType is equal to Self until the first null character is found. An exception is the terminating null character of Self which is ignored. Read more
source§

impl Hash for CStr8

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
source§

impl Ord for CStr8

source§

fn cmp(&self, other: &CStr8) -> Ordering

This method returns an Ordering between self and other. Read more
source§

impl PartialEq for CStr8

source§

fn eq(&self, other: &CStr8) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for CStr8

source§

fn partial_cmp(&self, other: &CStr8) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<'a> TryFrom<&'a CStr> for &'a CStr8

§

type Error = FromSliceWithNulError

The type returned in the event of a conversion error.
source§

fn try_from(cstr: &'a CStr) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl Eq for CStr8

source§

impl StructuralPartialEq for CStr8

Auto Trait Implementations§

§

impl Freeze for CStr8

§

impl RefUnwindSafe for CStr8

§

impl Send for CStr8

§

impl !Sized for CStr8

§

impl Sync for CStr8

§

impl Unpin for CStr8

§

impl UnwindSafe for CStr8

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more