Struct uefi::data_types::CString16

source ·
pub struct CString16(/* private fields */);
Available on crate feature alloc only.
Expand description

An owned UCS-2 null-terminated string.

For convenience, a CString16 is comparable with &str and String from the standard library through the trait EqStrUntilNul.

§Examples

Round-trip conversion from a &str to a CString16 and back:

use uefi::CString16;

let s = CString16::try_from("abc").unwrap();
assert_eq!(s.to_string(), "abc");

Implementations§

source§

impl CString16

source

pub fn new() -> Self

Creates a new empty string with a terminating null character.

source

pub fn push(&mut self, char: Char16)

Inserts a character at the end of the string, right before the null character.

§Panics

Panics if the char is a null character.

source

pub fn push_str(&mut self, str: &CStr16)

Extends the string with the given CStr16. The null character is automatically kept at the end.

source

pub fn replace_char(&mut self, search: Char16, replace: Char16)

Replaces all chars in the string with the replace value in-place.

source

pub fn num_chars(&self) -> usize

Returns the number of characters without the trailing null character.

source

pub fn is_empty(&self) -> bool

Returns if the string is empty. This ignores the null character.

Methods from Deref<Target = CStr16>§

source

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

Returns the inner pointer to this C16 string.

source

pub fn as_slice(&self) -> &[Char16]

Get the underlying Char16s as slice without the trailing null.

source

pub fn as_slice_with_nul(&self) -> &[Char16]

Get the underlying Char16s as slice including the trailing null.

source

pub fn to_u16_slice(&self) -> &[u16]

Converts this C string to a u16 slice without the trailing null.

source

pub fn to_u16_slice_with_nul(&self) -> &[u16]

Converts this C string to a u16 slice containing the trailing null.

source

pub fn iter(&self) -> CStr16Iter<'_>

Returns an iterator over this C string

source

pub fn num_chars(&self) -> usize

Returns the number of characters without the trailing null. character

source

pub fn is_empty(&self) -> bool

Returns if the string is empty. This ignores the null character.

source

pub fn num_bytes(&self) -> usize

Get the number of bytes in the string (including the trailing null).

source

pub fn is_ascii(&self) -> bool

Checks if all characters in this string are within the ASCII range.

source

pub fn as_str_in_buf(&self, buf: &mut dyn Write) -> Result

Writes each Char16 as a char (4 bytes long in Rust language) into the buffer. It is up to the implementer of core::fmt::Write to convert the char to a string with proper encoding/charset. For example, in the case of alloc::string::String all Rust chars (UTF-32) get converted to UTF-8.

§Example
let firmware_vendor_c16_str: CStr16 = ...;
// crate "arrayvec" uses stack-allocated arrays for Strings => no heap allocations
let mut buf = arrayvec::ArrayString::<128>::new();
firmware_vendor_c16_str.as_str_in_buf(&mut buf);
log::info!("as rust str: {}", buf.as_str());
source

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

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

Trait Implementations§

source§

impl AsRef<CStr16> for CString16

source§

fn as_ref(&self) -> &CStr16

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

impl Borrow<CStr16> for CString16

source§

fn borrow(&self) -> &CStr16

Immutably borrows from an owned value. Read more
source§

impl Clone for CString16

source§

fn clone(&self) -> CString16

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for CString16

source§

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

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

impl Default for CString16

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Deref for CString16

§

type Target = CStr16

The resulting type after dereferencing.
source§

fn deref(&self) -> &CStr16

Dereferences the value.
source§

impl Display for CString16

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 CString16

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 From<&CStr16> for CString16

source§

fn from(value: &CStr16) -> Self

Converts to this type from the input type.
source§

impl From<&CString16> for String

source§

fn from(value: &CString16) -> Self

Converts to this type from the input type.
source§

impl From<CString16> for PathBuf

source§

fn from(value: CString16) -> Self

Converts to this type from the input type.
source§

impl Hash for CString16

source§

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

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

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Ord for CString16

source§

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

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

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq<&CStr16> for CString16

source§

fn eq(&self, other: &&CStr16) -> 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 PartialEq<CString16> for &CStr16

source§

fn eq(&self, other: &CString16) -> 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 PartialEq for CString16

source§

fn eq(&self, other: &CString16) -> 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 CString16

source§

fn partial_cmp(&self, other: &CString16) -> 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<&UnalignedSlice<'a, u16>> for CString16

§

type Error = FromSliceWithNulError

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

fn try_from(input: &UnalignedSlice<'_, u16>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<&str> for CString16

§

type Error = FromStrError

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

fn try_from(input: &str) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Vec<u16>> for CString16

§

type Error = FromSliceWithNulError

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

fn try_from(input: Vec<u16>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl Eq for CString16

source§

impl StructuralPartialEq for CString16

Auto Trait Implementations§

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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Pointee for T

§

type Metadata = ()

The type for metadata in pointers and references to Self.
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

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

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.