Struct ucs2::Ucs2LeSlice
source · pub struct Ucs2LeSlice(/* private fields */);
Expand description
Wrapper around [u8]
containing a valid null-terminated UCS-2 LE string.
This type is not FFI compatible with *const u16
!
Because Ucs2LeSlice
uses a [u8]
as the backing data type (as opposed to
a [u16]
), the data is not guaranteed to be u16
aligned!
§Example
let raw = [b'O', 0, b'K', 0, 0, 0];
let s = Ucs2LeSlice::from_slice_with_nul(&raw).unwrap();
assert_eq!(s.as_bytes().len(), raw.len());
assert_eq!(s.to_string(), "OK");
Implementations§
source§impl Ucs2LeSlice
impl Ucs2LeSlice
sourcepub fn from_slice_with_nul(buf: &[u8]) -> Result<&Ucs2LeSlice, Ucs2ParseError>
pub fn from_slice_with_nul(buf: &[u8]) -> Result<&Ucs2LeSlice, Ucs2ParseError>
Validate that the provided &[u8]
is a valid null-terminated UCS-2 LE
string, truncating the slice to the position of the first null u16.
sourcepub fn as_bytes_without_nul(&self) -> &[u8] ⓘ
pub fn as_bytes_without_nul(&self) -> &[u8] ⓘ
View the underlying data as raw bytes, without the trailing null u16
.
sourcepub fn to_ucs2_le_vec(&self) -> Ucs2LeVec
pub fn to_ucs2_le_vec(&self) -> Ucs2LeVec
Copies self
into a new Ucs2LeVec
.
Trait Implementations§
source§impl AsRef<Ucs2LeSlice> for Ucs2LeVec
impl AsRef<Ucs2LeSlice> for Ucs2LeVec
source§fn as_ref(&self) -> &Ucs2LeSlice
fn as_ref(&self) -> &Ucs2LeSlice
Converts this type into a shared reference of the (usually inferred) input type.
source§impl Borrow<Ucs2LeSlice> for Ucs2LeVec
impl Borrow<Ucs2LeSlice> for Ucs2LeVec
source§fn borrow(&self) -> &Ucs2LeSlice
fn borrow(&self) -> &Ucs2LeSlice
Immutably borrows from an owned value. Read more
source§impl Debug for Ucs2LeSlice
impl Debug for Ucs2LeSlice
source§impl<'a> Default for &'a Ucs2LeSlice
impl<'a> Default for &'a Ucs2LeSlice
source§fn default() -> &'a Ucs2LeSlice
fn default() -> &'a Ucs2LeSlice
Returns the “default value” for a type. Read more
source§impl Display for Ucs2LeSlice
impl Display for Ucs2LeSlice
source§impl<'a> From<&'a Ucs2LeSlice> for Cow<'a, Ucs2LeSlice>
impl<'a> From<&'a Ucs2LeSlice> for Cow<'a, Ucs2LeSlice>
source§fn from(val: &'a Ucs2LeSlice) -> Self
fn from(val: &'a Ucs2LeSlice) -> Self
Converts to this type from the input type.