pub struct Char8String(/* private fields */);Expand description
An owned, heap-backed, NUL-terminated CHAR8 (ASCII / ISO-Latin-1) string.
This is the CHAR8 analogue of alloc::string::String. It dereferences to Char8Str, so all
borrowed operations are available on an owned value.
§Examples
use patina::string::Char8String;
let s = Char8String::try_from_str("Firmware").unwrap();
assert_eq!(s.len(), 8);
assert!(s == "Firmware");Implementations§
Source§impl Char8String
impl Char8String
Sourcepub fn try_from_str(s: &str) -> Result<Self, StringError>
pub fn try_from_str(s: &str) -> Result<Self, StringError>
Creates a Char8String by encoding a Rust str as Latin-1.
§Errors
Returns StringError::InteriorNul if the input contains a NUL character, or
StringError::NotLatin1 if it contains a code point above U+00FF.
Sourcepub fn from_bytes_with_nul(bytes: Vec<u8>) -> Result<Self, StringError>
pub fn from_bytes_with_nul(bytes: Vec<u8>) -> Result<Self, StringError>
Creates a Char8String from a Vec<u8> that ends with a NUL terminator.
This validates bytes the same way Char8Str::from_bytes_with_nul does, then takes
ownership of the buffer directly instead of cloning it.
§Errors
Returns StringError::MissingNulTerminator if bytes does not end with a NUL, or
StringError::InteriorNul if a NUL appears before the end.
Sourcepub unsafe fn from_bytes_with_nul_unchecked(bytes: Vec<u8>) -> Self
pub unsafe fn from_bytes_with_nul_unchecked(bytes: Vec<u8>) -> Self
Creates a Char8String from a NUL-terminated Vec<u8> without validating its contents.
§Safety
The caller must ensure that bytes ends with a single NUL terminator and contains no interior
NUL.
Sourcepub fn as_char8_str(&self) -> &Char8Str
pub fn as_char8_str(&self) -> &Char8Str
Borrows this owned string as a Char8Str.
Sourcepub fn into_bytes_with_nul(self) -> Vec<u8> ⓘ
pub fn into_bytes_with_nul(self) -> Vec<u8> ⓘ
Consumes the string and returns the backing bytes, including the trailing NUL.
Methods from Deref<Target = Char8Str>§
pub const EMPTY: &'static Char8Str
Sourcepub fn as_ptr(&self) -> *const u8
pub fn as_ptr(&self) -> *const u8
Returns a pointer to the first byte, suitable for passing to extern "efiapi" interfaces.
The pointed-to sequence is always NUL-terminated.
Sourcepub fn as_bytes_with_nul(&self) -> &[u8] ⓘ
pub fn as_bytes_with_nul(&self) -> &[u8] ⓘ
Returns the bytes including the trailing NUL terminator.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of characters, excluding the trailing NUL terminator.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the string contains no characters (only the NUL terminator).
Trait Implementations§
Source§impl Borrow<Char8Str> for Char8String
Available on crate features alloc only.
impl Borrow<Char8Str> for Char8String
alloc only.Source§impl Clone for Char8String
impl Clone for Char8String
Source§fn clone(&self) -> Char8String
fn clone(&self) -> Char8String
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Char8String
Available on crate features alloc only.
impl Debug for Char8String
alloc only.Source§impl Default for Char8String
Available on crate features alloc only.
impl Default for Char8String
alloc only.Source§impl Deref for Char8String
Available on crate features alloc only.
impl Deref for Char8String
alloc only.Source§impl Display for Char8String
Available on crate features alloc only.
impl Display for Char8String
alloc only.impl Eq for Char8String
Source§impl From<&Char8Str> for Char8String
Available on crate features alloc only.
impl From<&Char8Str> for Char8String
alloc only.Source§impl From<&Char8String> for Char16String
Available on crate features alloc only.
impl From<&Char8String> for Char16String
alloc only.Source§fn from(value: &Char8String) -> Self
fn from(value: &Char8String) -> Self
Source§impl<const N: usize> From<Char8Array<N>> for Char8String
Available on crate features alloc only.
impl<const N: usize> From<Char8Array<N>> for Char8String
alloc only.Source§fn from(value: Char8Array<N>) -> Self
fn from(value: Char8Array<N>) -> Self
Converts a fixed-capacity array to a heap-owned string, dropping the const capacity N.
Source§impl From<Char8String> for Char16String
Available on crate features alloc only.
impl From<Char8String> for Char16String
alloc only.Source§fn from(value: Char8String) -> Self
fn from(value: Char8String) -> Self
Source§impl Hash for Char8String
impl Hash for Char8String
Source§impl Ord for Char8String
impl Ord for Char8String
Source§fn cmp(&self, other: &Char8String) -> Ordering
fn cmp(&self, other: &Char8String) -> Ordering
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for Char8String
impl PartialEq for Char8String
Source§impl PartialEq<&Char8Str> for Char8String
Available on crate features alloc only.
impl PartialEq<&Char8Str> for Char8String
alloc only.Source§impl PartialEq<&str> for Char8String
Available on crate features alloc only.
impl PartialEq<&str> for Char8String
alloc only.Source§impl PartialEq<Char8Str> for Char8String
Available on crate features alloc only.
impl PartialEq<Char8Str> for Char8String
alloc only.Source§impl PartialEq<Char8String> for str
Available on crate features alloc only.
impl PartialEq<Char8String> for str
alloc only.Source§impl PartialEq<Char8String> for Char8Str
Available on crate features alloc only.
impl PartialEq<Char8String> for Char8Str
alloc only.Source§impl PartialEq<str> for Char8String
Available on crate features alloc only.
impl PartialEq<str> for Char8String
alloc only.Source§impl PartialOrd for Char8String
impl PartialOrd for Char8String
impl StructuralPartialEq for Char8String
Source§impl<'a> TryFrom<&'a str> for Char8String
Available on crate features alloc only.
impl<'a> TryFrom<&'a str> for Char8String
alloc only.Source§impl TryFrom<&Char16Str> for Char8String
Available on crate features alloc only.
impl TryFrom<&Char16Str> for Char8String
alloc only.Source§type Error = StringError
type Error = StringError
Source§impl TryFrom<&Char16String> for Char8String
Available on crate features alloc only.
impl TryFrom<&Char16String> for Char8String
alloc only.Source§type Error = StringError
type Error = StringError
Source§fn try_from(value: &Char16String) -> Result<Self, StringError>
fn try_from(value: &Char16String) -> Result<Self, StringError>
Source§impl TryFrom<Char16String> for Char8String
Available on crate features alloc only.
impl TryFrom<Char16String> for Char8String
alloc only.Source§type Error = StringError
type Error = StringError
Source§fn try_from(value: Char16String) -> Result<Self, StringError>
fn try_from(value: Char16String) -> Result<Self, StringError>
Auto Trait Implementations§
impl Freeze for Char8String
impl RefUnwindSafe for Char8String
impl Send for Char8String
impl Sync for Char8String
impl Unpin for Char8String
impl UnsafeUnpin for Char8String
impl UnwindSafe for Char8String
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.