WString

Struct WString 

Source
pub struct WString<const LEN: usize>(/* private fields */);
Expand description

Represents a fixed-length wide string.

This type can be created from a &[u16] if its length does not exceed the fixed length. It can be created from a &str if its length, encoded in UTF16, does not exceed the fixed length.

It can be freely converted from and to a [u16; N] array, and to a Vec<u16> where it will be cut at the first null.

It can be converted to a Rust String if it is properly UTF16 encoded.

Implementations§

Source§

impl<const LEN: usize> WString<LEN>

Source

pub fn new() -> Self

Create a new empty string.

Source

pub fn len(&self) -> usize

Return the number of code units up to the first null.

Source

pub fn is_empty(&self) -> bool

Returns true if the string is empty.

Source

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

Get the slice up to the first null code unit.

Source

pub fn backing_array(&mut self) -> &mut [u16; LEN]

Get a reference to the full array of code units.

Trait Implementations§

Source§

impl<const LEN: usize> AsBytes for WString<LEN>

Source§

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

Gets the bytes of this value. Read more
Source§

fn as_bytes_mut(&mut self) -> &mut [u8]
where Self: FromBytes,

Gets the bytes of this value mutably. Read more
Source§

fn write_to(&self, bytes: &mut [u8]) -> Option<()>

Writes a copy of self to bytes. Read more
Source§

fn write_to_prefix(&self, bytes: &mut [u8]) -> Option<()>

Writes a copy of self to the prefix of bytes. Read more
Source§

fn write_to_suffix(&self, bytes: &mut [u8]) -> Option<()>

Writes a copy of self to the suffix of bytes. Read more
Source§

impl<const LEN: usize> Clone for WString<LEN>

Source§

fn clone(&self) -> WString<LEN>

Returns a duplicate 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<const LEN: usize> Debug for WString<LEN>

Source§

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

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

impl<const LEN: usize> Default for WString<LEN>

Source§

fn default() -> Self

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

impl<const LEN: usize> From<[u16; LEN]> for WString<LEN>

Source§

fn from(arr: [u16; LEN]) -> Self

Converts to this type from the input type.
Source§

impl<const LEN: usize> From<WString<LEN>> for [u16; LEN]

Source§

fn from(wstr: WString<LEN>) -> Self

Converts to this type from the input type.
Source§

impl<const LEN: usize> From<WString<LEN>> for Vec<u16>

Source§

fn from(wstr: WString<LEN>) -> Self

Converts to this type from the input type.
Source§

impl<const LEN: usize> FromBytes for WString<LEN>

Source§

fn ref_from(bytes: &[u8]) -> Option<&Self>
where Self: Sized,

Interprets the given bytes as a &Self without copying. Read more
Source§

fn ref_from_prefix(bytes: &[u8]) -> Option<&Self>
where Self: Sized,

Interprets the prefix of the given bytes as a &Self without copying. Read more
Source§

fn ref_from_suffix(bytes: &[u8]) -> Option<&Self>
where Self: Sized,

Interprets the suffix of the given bytes as a &Self without copying. Read more
Source§

fn mut_from(bytes: &mut [u8]) -> Option<&mut Self>
where Self: Sized + AsBytes,

Interprets the given bytes as a &mut Self without copying. Read more
Source§

fn mut_from_prefix(bytes: &mut [u8]) -> Option<&mut Self>
where Self: Sized + AsBytes,

Interprets the prefix of the given bytes as a &mut Self without copying. Read more
Source§

fn mut_from_suffix(bytes: &mut [u8]) -> Option<&mut Self>
where Self: Sized + AsBytes,

Interprets the suffix of the given bytes as a &mut Self without copying. Read more
Source§

fn slice_from(bytes: &[u8]) -> Option<&[Self]>
where Self: Sized,

Interprets the given bytes as a &[Self] without copying. Read more
Source§

fn slice_from_prefix(bytes: &[u8], count: usize) -> Option<(&[Self], &[u8])>
where Self: Sized,

Interprets the prefix of the given bytes as a &[Self] with length equal to count without copying. Read more
Source§

fn slice_from_suffix(bytes: &[u8], count: usize) -> Option<(&[u8], &[Self])>
where Self: Sized,

Interprets the suffix of the given bytes as a &[Self] with length equal to count without copying. Read more
Source§

fn mut_slice_from(bytes: &mut [u8]) -> Option<&mut [Self]>
where Self: Sized + AsBytes,

Interprets the given bytes as a &mut [Self] without copying. Read more
Source§

fn mut_slice_from_prefix( bytes: &mut [u8], count: usize, ) -> Option<(&mut [Self], &mut [u8])>
where Self: Sized + AsBytes,

Interprets the prefix of the given bytes as a &mut [Self] with length equal to count without copying. Read more
Source§

fn mut_slice_from_suffix( bytes: &mut [u8], count: usize, ) -> Option<(&mut [u8], &mut [Self])>
where Self: Sized + AsBytes,

Interprets the suffix of the given bytes as a &mut [Self] with length equal to count without copying. Read more
Source§

fn read_from(bytes: &[u8]) -> Option<Self>
where Self: Sized,

Reads a copy of Self from bytes. Read more
Source§

fn read_from_prefix(bytes: &[u8]) -> Option<Self>
where Self: Sized,

Reads a copy of Self from the prefix of bytes. Read more
Source§

fn read_from_suffix(bytes: &[u8]) -> Option<Self>
where Self: Sized,

Reads a copy of Self from the suffix of bytes. Read more
Source§

impl<const LEN: usize> FromZeroes for WString<LEN>

Source§

fn zero(&mut self)

Overwrites self with zeroes. Read more
Source§

fn new_zeroed() -> Self
where Self: Sized,

Creates an instance of Self from zeroed bytes. Read more
Source§

impl<const LEN: usize> PartialEq<&[u16]> for WString<LEN>

Source§

fn eq(&self, other: &&[u16]) -> 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<const LEN: usize> PartialEq<&str> for WString<LEN>

Source§

fn eq(&self, other: &&str) -> 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<const LEN: usize> PartialEq for WString<LEN>

Source§

fn eq(&self, other: &Self) -> 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<const LEN: usize> TryFrom<&[u16]> for WString<LEN>

Source§

type Error = ()

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

fn try_from(arr: &[u16]) -> Result<Self, ()>

Performs the conversion.
Source§

impl<const LEN: usize> TryFrom<&str> for WString<LEN>

Source§

type Error = ()

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

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

Performs the conversion.
Source§

impl<const LEN: usize> TryFrom<WString<LEN>> for String

Source§

type Error = DecodeUtf16Error

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

fn try_from(wstr: WString<LEN>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<const LEN: usize> Copy for WString<LEN>

Auto Trait Implementations§

§

impl<const LEN: usize> Freeze for WString<LEN>

§

impl<const LEN: usize> RefUnwindSafe for WString<LEN>

§

impl<const LEN: usize> Send for WString<LEN>

§

impl<const LEN: usize> Sync for WString<LEN>

§

impl<const LEN: usize> Unpin for WString<LEN>

§

impl<const LEN: usize> UnwindSafe for WString<LEN>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

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

Source§

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.