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>
impl<const N: usize> StaticWString<N>
Sourcepub const fn new() -> Self
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.
Sourcepub const fn len(&self) -> usize
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);Sourcepub const fn capacity(&self) -> usize
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);Sourcepub const fn is_empty(&self) -> bool
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);Sourcepub const fn as_slice(&self) -> &[u16]
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]);Sourcepub const fn as_mut_slice(&mut self) -> &mut [u16]
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"));Sourcepub const fn as_ptr(&self) -> *const u16
pub const fn as_ptr(&self) -> *const u16
Returns an immutable pointer to the first character of this string.
Sourcepub const fn as_mut_ptr(&mut self) -> *mut u16
pub const fn as_mut_ptr(&mut self) -> *mut u16
Returns a mutable pointer to the first character of this string.
Sourcepub fn push_char(&mut self, ch: char)
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]);Sourcepub fn push_str(&mut self, s: &str)
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!"));Sourcepub fn insert_char(&mut self, index: usize, ch: char)
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!"));Sourcepub fn insert_str(&mut self, index: usize, s: &str)
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>
impl<const N: usize> Clone for StaticWString<N>
Source§fn clone(&self) -> StaticWString<N>
fn clone(&self) -> StaticWString<N>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more