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

source

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.

source

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

View the underlying data as raw bytes.

source

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

View the underlying data as raw bytes, without the trailing null u16.

source

pub fn to_ucs2_le_vec(&self) -> Ucs2LeVec

Copies self into a new Ucs2LeVec.

Trait Implementations§

source§

impl AsRef<Ucs2LeSlice> for Ucs2LeVec

source§

fn as_ref(&self) -> &Ucs2LeSlice

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

impl Borrow<Ucs2LeSlice> for Ucs2LeVec

source§

fn borrow(&self) -> &Ucs2LeSlice

Immutably borrows from an owned value. Read more
source§

impl Debug for Ucs2LeSlice

source§

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

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

impl<'a> Default for &'a Ucs2LeSlice

source§

fn default() -> &'a Ucs2LeSlice

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

impl Display for Ucs2LeSlice

source§

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

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

impl<'a> From<&'a Ucs2LeSlice> for Cow<'a, Ucs2LeSlice>

source§

fn from(val: &'a Ucs2LeSlice) -> Self

Converts to this type from the input type.
source§

impl Hash for Ucs2LeSlice

source§

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

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

impl Ord for Ucs2LeSlice

source§

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

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

impl PartialEq for Ucs2LeSlice

source§

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

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

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

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

impl PartialOrd for Ucs2LeSlice

source§

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

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

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

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

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

impl ToOwned for Ucs2LeSlice

source§

type Owned = Ucs2LeVec

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> Ucs2LeVec

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

fn clone_into(&self, target: &mut Self::Owned)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl Eq for Ucs2LeSlice

source§

impl StructuralPartialEq for Ucs2LeSlice

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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more