Struct uefi::data_types::CString16
source · pub struct CString16(/* private fields */);
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
impl CString16
sourcepub fn push(&mut self, char: Char16)
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.
sourcepub fn push_str(&mut self, str: &CStr16)
pub fn push_str(&mut self, str: &CStr16)
Extends the string with the given CStr16
. The null character is
automatically kept at the end.
sourcepub fn replace_char(&mut self, search: Char16, replace: Char16)
pub fn replace_char(&mut self, search: Char16, replace: Char16)
Replaces all chars in the string with the replace value in-place.
Methods from Deref<Target = CStr16>§
sourcepub fn as_slice(&self) -> &[Char16]
pub fn as_slice(&self) -> &[Char16]
Get the underlying Char16
s as slice without the trailing null.
sourcepub fn as_slice_with_nul(&self) -> &[Char16]
pub fn as_slice_with_nul(&self) -> &[Char16]
Get the underlying Char16
s as slice including the trailing null.
sourcepub fn to_u16_slice(&self) -> &[u16]
pub fn to_u16_slice(&self) -> &[u16]
Converts this C string to a u16 slice without the trailing null.
sourcepub fn to_u16_slice_with_nul(&self) -> &[u16]
pub fn to_u16_slice_with_nul(&self) -> &[u16]
Converts this C string to a u16 slice containing the trailing null.
sourcepub fn num_chars(&self) -> usize
pub fn num_chars(&self) -> usize
Returns the number of characters without the trailing null. character
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns if the string is empty. This ignores the null character.
sourcepub fn num_bytes(&self) -> usize
pub fn num_bytes(&self) -> usize
Get the number of bytes in the string (including the trailing null).
sourcepub fn is_ascii(&self) -> bool
pub fn is_ascii(&self) -> bool
Checks if all characters in this string are within the ASCII range.
sourcepub fn as_str_in_buf(&self, buf: &mut dyn Write) -> Result
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());
Trait Implementations§
source§impl Ord for CString16
impl Ord for CString16
source§impl PartialOrd for CString16
impl PartialOrd for CString16
impl Eq for CString16
impl StructuralPartialEq for CString16
Auto Trait Implementations§
impl Freeze for CString16
impl RefUnwindSafe for CString16
impl Send for CString16
impl Sync for CString16
impl Unpin for CString16
impl UnwindSafe for CString16
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)