Skip to main content

StaticWString

Struct StaticWString 

Source
pub struct StaticWString<const N: usize> { /* private fields */ }
Expand description

The StaticWString is a fixed-capacity UTF-16 string object.

Implementations§

Source§

impl<const N: usize> StaticWString<N>

Source

pub const fn new() -> Self

Creates a new empty StaticWString.

Given that the string is empty, the buffer that contains the string isn’t initialized. This means the initial operation is very inexpensive.

Source

pub const fn len(&self) -> usize

Obtains the length of this string, in number of UTF-16 characters.
If a character cannot fit in a single UTF-16 range (e.g.: emoji), it will be counted as 2 characters.

§Example
use static_collections::ffi::wstring::StaticWString;
let mut s:StaticWString<32>=StaticWString::new();
s.push_char('a');
assert_eq!(s.len(),1);
s.push_char('😀');
assert_eq!(s.len(),3);
Source

pub const fn capacity(&self) -> usize

Obtains the capacity of this string, in number of UTF-16 characters.

§Example
use static_collections::ffi::wstring::StaticWString;
let s:StaticWString<32>=StaticWString::new();
assert_eq!(s.capacity(),32);
Source

pub const fn is_empty(&self) -> bool

Checks if this string is empty.

§Example
use static_collections::ffi::wstring::StaticWString;
let mut s:StaticWString<32>=StaticWString::new();
assert!(s.is_empty());
s.push_char('a');
s.push_char('😀');
assert_eq!(s.is_empty(),false);
Source

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

Returns an immutable slice of this string in &[u16] form.

§Example
use static_collections::ffi::wstring::StaticWString;
let mut s:StaticWString<32>=StaticWString::new();
s.push_char('😀');
assert_eq!(s.as_slice(),[0xD83D,0xDE00]);
Source

pub const fn as_mut_slice(&mut self) -> &mut [u16]

Returns a mutable slice of this string in &mut [u16] form.

§Example
use static_collections::ffi::wstring::StaticWString;
use utf16_lit::utf16;
let mut s:StaticWString<32>=StaticWString::new();
s.push_char('😀');
let x=s.as_mut_slice();
assert_eq!(x,[0xD83D,0xDE00]);
x[0]=b'1' as u16;
x[1]=b'0' as u16;
assert_eq!(s,utf16!("10"));
Source

pub const fn as_ptr(&self) -> *const u16

Returns an immutable pointer to the first character of this string.

Source

pub const fn as_mut_ptr(&mut self) -> *mut u16

Returns a mutable pointer to the first character of this string.

Source

pub fn push_char(&mut self, ch: char)

Inserts a character to the end of the string.

§Example
use static_collections::ffi::wstring::StaticWString;
let mut s:StaticWString<32>=StaticWString::new();
s.push_char('a');
assert_eq!(s.len(),1);
assert_eq!(s.as_slice(),[b'a' as u16]);
Source

pub fn push_str(&mut self, s: &str)

Inserts a UTF-8 encoded string-slice to the end of the string.

§Example
use static_collections::ffi::wstring::StaticWString;
use utf16_lit::utf16;
let mut s:StaticWString<32>=StaticWString::new();
s.push_str("Hello, World!");
assert_eq!(s.as_slice(),utf16!("Hello, World!"));
Source

pub fn insert_char(&mut self, index: usize, ch: char)

Inserts a character to the position specifed by index.

§Example
use static_collections::ffi::wstring::StaticWString;
use utf16_lit::utf16;
let mut s:StaticWString<32>=StaticWString::from("Hello World!");
s.insert_char(5,',');
assert_eq!(s.as_slice(),utf16!("Hello, World!"));
Source

pub fn insert_str(&mut self, index: usize, s: &str)

Inserts a UTF-8-encoded string-slice to the position specified by index.

§Example
use static_collections::ffi::wstring::StaticWString;
use utf16_lit::utf16;
let mut s:StaticWString<32>=StaticWString::from("123789");
s.insert_str(3,"456");
assert_eq!(s.as_slice(),utf16!("123456789"));

Trait Implementations§

Source§

impl<const N: usize> Clone for StaticWString<N>

Source§

fn clone(&self) -> StaticWString<N>

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 N: usize> Debug for StaticWString<N>

Source§

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

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

impl<const N: usize> Default for StaticWString<N>

Source§

fn default() -> StaticWString<N>

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

impl<const N: usize> Display for StaticWString<N>

Source§

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

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

impl<const N: usize> From<&str> for StaticWString<N>

Source§

fn from(value: &str) -> Self

Converts to this type from the input type.
Source§

impl<I: SliceIndex<[u16]>, const N: usize> Index<I> for StaticWString<N>

Source§

type Output = <I as SliceIndex<[u16]>>::Output

The returned type after indexing.
Source§

fn index(&self, index: I) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<I: SliceIndex<[u16]>, const N: usize> IndexMut<I> for StaticWString<N>

Source§

fn index_mut(&mut self, index: I) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<const N: usize> PartialEq<[u16]> for StaticWString<N>

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 M: usize, const N: usize> PartialEq<[u16; M]> for StaticWString<N>

Source§

fn eq(&self, other: &[u16; M]) -> 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 N: usize> PartialOrd<[u16]> for StaticWString<N>

Source§

fn partial_cmp(&self, other: &[u16]) -> 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<const M: usize, const N: usize> PartialOrd<[u16; M]> for StaticWString<N>

Source§

fn partial_cmp(&self, other: &[u16; M]) -> 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<const N: usize> Write for StaticWString<N>

Source§

fn write_char(&mut self, c: char) -> Result

Writes a char into this writer, returning whether the write succeeded. Read more
Source§

fn write_str(&mut self, s: &str) -> Result

Writes a string slice into this writer, returning whether the write succeeded. Read more
1.0.0 · Source§

fn write_fmt(&mut self, args: Arguments<'_>) -> Result<(), Error>

Glue for usage of the write! macro with implementors of this trait. Read more

Auto Trait Implementations§

§

impl<const N: usize> Freeze for StaticWString<N>

§

impl<const N: usize> RefUnwindSafe for StaticWString<N>

§

impl<const N: usize> Send for StaticWString<N>

§

impl<const N: usize> Sync for StaticWString<N>

§

impl<const N: usize> Unpin for StaticWString<N>

§

impl<const N: usize> UnsafeUnpin for StaticWString<N>

§

impl<const N: usize> UnwindSafe for StaticWString<N>

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