Skip to main content

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

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<B>(&self, bytes: B) -> Option<()>
where B: ByteSliceMut,

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

fn write_to_prefix<B>(&self, bytes: B) -> Option<()>
where B: ByteSliceMut,

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

fn write_to_suffix<B>(&self, bytes: B) -> Option<()>
where B: ByteSliceMut,

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 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

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

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<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> 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> FromBytes for WString<LEN>

Source§

fn read_from<B>(bytes: B) -> Option<Self>
where B: ByteSlice, Self: Sized,

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

fn read_from_prefix<B>(bytes: B) -> Option<Self>
where B: ByteSlice, Self: Sized,

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

fn read_from_suffix<B>(bytes: B) -> Option<Self>
where B: ByteSlice, Self: Sized,

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

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

Creates an instance of Self from zeroed bytes.
Source§

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

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

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

Source§

fn eq(&self, other: &&[u16]) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

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

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
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.

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> UnsafeUnpin 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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more