pub type WideString = U32String;
Expand description
Aliased Type§
struct WideString { /* private fields */ }
Implementations
Source§impl U32String
impl U32String
Sourcepub fn from_vec(raw: impl Into<Vec<u32>>) -> Self
pub fn from_vec(raw: impl Into<Vec<u32>>) -> Self
Constructs a wide string from a vector.
No checks are made on the contents of the vector. It may or may not be valid character data.
§Examples
use widestring::U16String;
let v = vec![84u16, 104u16, 101u16]; // 'T' 'h' 'e'
// Create a wide string from the vector
let wstr = U16String::from_vec(v);
use widestring::U32String;
let v = vec![84u32, 104u32, 101u32]; // 'T' 'h' 'e'
// Create a wide string from the vector
let wstr = U32String::from_vec(v);
Sourcepub unsafe fn from_ptr(p: *const u32, len: usize) -> Self
pub unsafe fn from_ptr(p: *const u32, len: usize) -> Self
Constructs a wide string copy from a pointer and a length.
The len
argument is the number of elements, not the number of bytes.
§Safety
This function is unsafe as there is no guarantee that the given pointer is valid for
len
elements.
In addition, the data must meet the safety conditions of std::slice::from_raw_parts.
§Panics
Panics if len
is greater than 0 but p
is a null pointer.
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Constructs a wide string with the given capacity.
The string will be able to hold exactly capacity
elements without reallocating.
If capacity
is set to 0, the string will not initially allocate.
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the capacity this wide string can hold without reallocating.
Sourcepub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
Reserves the capacity for at least additional
more capacity to be inserted in the
given wide string.
More space may be reserved to avoid frequent allocations.
Sourcepub fn reserve_exact(&mut self, additional: usize)
pub fn reserve_exact(&mut self, additional: usize)
Reserves the minimum capacity for exactly additional
more capacity to be inserted
in the given wide string. Does nothing if the capacity is already sufficient.
Note that the allocator may give more space than is requested. Therefore capacity
can not be relied upon to be precisely minimal. Prefer reserve
if
future insertions are expected.
Sourcepub fn into_vec(self) -> Vec<u32>
pub fn into_vec(self) -> Vec<u32>
Converts the string into a Vec
, consuming the string in the process.
Sourcepub fn as_mut_ustr(&mut self) -> &mut U32Str
pub fn as_mut_ustr(&mut self) -> &mut U32Str
Converts to a mutable wide string slice.
Sourcepub fn as_mut_vec(&mut self) -> &mut Vec<u32>
pub fn as_mut_vec(&mut self) -> &mut Vec<u32>
Returns a mutable reference to the contents of this string.
Sourcepub fn push(&mut self, s: impl AsRef<U32Str>)
pub fn push(&mut self, s: impl AsRef<U32Str>)
Extends the string with the given string slice.
No checks are performed on the strings. It is possible to end up nul values inside the string, or invalid encoding, and it is up to the caller to determine if that is acceptable.
§Examples
use widestring::U32String;
let s = "MyString";
let mut wstr = U32String::from_str(s);
let cloned = wstr.clone();
// Push the clone to the end, repeating the string twice.
wstr.push(cloned);
assert_eq!(wstr.to_string().unwrap(), "MyStringMyString");
Sourcepub fn push_slice(&mut self, s: impl AsRef<[u32]>)
pub fn push_slice(&mut self, s: impl AsRef<[u32]>)
Extends the string with the given slice.
No checks are performed on the strings. It is possible to end up nul values inside the string, or invalid encoding, and it is up to the caller to determine if that is acceptable.
§Examples
use widestring::U32String;
let s = "MyString";
let mut wstr = U32String::from_str(s);
let cloned = wstr.clone();
// Push the clone to the end, repeating the string twice.
wstr.push_slice(cloned);
assert_eq!(wstr.to_string().unwrap(), "MyStringMyString");
Sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Shrinks the capacity of the wide string to match its length.
Sourcepub fn shrink_to(&mut self, min_capacity: usize)
pub fn shrink_to(&mut self, min_capacity: usize)
Shrinks the capacity of this string with a lower bound.
The capacity will remain at least as large as both the length and the supplied value.
If the current capacity is less than the lower limit, this is a no-op.
Sourcepub fn into_boxed_ustr(self) -> Box<U32Str>
pub fn into_boxed_ustr(self) -> Box<U32Str>
Converts this wide string into a boxed string slice.
§Examples
use widestring::{U32String, U32Str};
let s = U32String::from_str("hello");
let b: Box<U32Str> = s.into_boxed_ustr();
Sourcepub fn truncate(&mut self, new_len: usize)
pub fn truncate(&mut self, new_len: usize)
Shortens this string to the specified length.
If new_len
is greater than the string’s current length, this has no effect.
Note that this method has no effect on the allocated capacity of the string.
Sourcepub fn insert_ustr(&mut self, idx: usize, string: &U32Str)
pub fn insert_ustr(&mut self, idx: usize, string: &U32Str)
Inserts a string slice into this string at a specified position.
This is an O(n) operation as it requires copying every element in the buffer.
§Panics
Panics if idx
is larger than the string’s length.
Sourcepub fn split_off(&mut self, at: usize) -> U32String
pub fn split_off(&mut self, at: usize) -> U32String
Splits the string into two at the given index.
Returns a newly allocated string. self
contains values [0, at)
, and the returned
string contains values [at, len)
.
Note that the capacity of self
does not change.
§Panics
Panics if at
is equal to or greater than the length of the string.
Sourcepub fn retain<F>(&mut self, f: F)
pub fn retain<F>(&mut self, f: F)
Retains only the elements specified by the predicate.
In other words, remove all elements e
such that f(e)
returns false
. This
method operates in place, visiting each element exactly once in the original order,
and preserves the order of the retained elements.
Sourcepub fn drain<R>(&mut self, range: R) -> Drain<'_, u32> ⓘwhere
R: RangeBounds<usize>,
pub fn drain<R>(&mut self, range: R) -> Drain<'_, u32> ⓘwhere
R: RangeBounds<usize>,
Creates a draining iterator that removes the specified range in the string and yields the removed elements.
Note: The element range is removed even if the iterator is not consumed until the end.
§Panics
Panics if the starting point or end point are out of bounds.
Sourcepub fn replace_range<R>(&mut self, range: R, replace_with: impl AsRef<U32Str>)where
R: RangeBounds<usize>,
pub fn replace_range<R>(&mut self, range: R, replace_with: impl AsRef<U32Str>)where
R: RangeBounds<usize>,
Removes the specified range in the string, and replaces it with the given string.
The given string doesn’t need to be the same length as the range.
§Panics
Panics if the starting point or end point are out of bounds.
Source§impl U32String
impl U32String
Sourcepub fn from_chars(raw: impl Into<Vec<char>>) -> Self
pub fn from_chars(raw: impl Into<Vec<char>>) -> Self
Sourcepub fn from_str<S: AsRef<str> + ?Sized>(s: &S) -> Self
pub fn from_str<S: AsRef<str> + ?Sized>(s: &S) -> Self
Constructs a U16String
copy from a str
, encoding it as UTF-32.
This makes a string copy of the str
. Since str
will always be valid UTF-8, the
resulting U32String
will also be valid UTF-32.
§Examples
use widestring::U32String;
let s = "MyString";
// Create a wide string from the string
let wstr = U32String::from_str(s);
assert_eq!(wstr.to_string().unwrap(), s);
Sourcepub fn from_os_str<S: AsRef<OsStr> + ?Sized>(s: &S) -> Self
pub fn from_os_str<S: AsRef<OsStr> + ?Sized>(s: &S) -> Self
Constructs a U32String
copy from an OsStr
.
This makes a string copy of the OsStr
. Since OsStr
makes no guarantees that it is valid data, there is no guarantee that the resulting
U32String
will be valid UTF-32.
Note that the encoding of OsStr
is platform-dependent, so on
some platforms this may make an encoding conversions, while on other platforms no changes to
the string will be made.
§Examples
use widestring::U32String;
let s = "MyString";
// Create a wide string from the string
let wstr = U32String::from_os_str(s);
assert_eq!(wstr.to_string().unwrap(), s);
Sourcepub unsafe fn from_char_ptr(p: *const char, len: usize) -> Self
pub unsafe fn from_char_ptr(p: *const char, len: usize) -> Self
Constructs a U32String
from a char
pointer and a length.
The len
argument is the number of char
elements, not the number of bytes.
§Safety
This function is unsafe as there is no guarantee that the given pointer is valid for len
elements.
In addition, the data must meet the safety conditions of std::slice::from_raw_parts.
§Panics
Panics if len
is greater than 0 but p
is a null pointer.
Sourcepub fn push_str(&mut self, s: impl AsRef<str>)
pub fn push_str(&mut self, s: impl AsRef<str>)
Extends the string with the given string slice, encoding it at UTF-32.
No checks are performed on the strings. It is possible to end up nul values inside the string, and it is up to the caller to determine if that is acceptable.
§Examples
use widestring::U32String;
let s = "MyString";
let mut wstr = U32String::from_str(s);
// Push the original to the end, repeating the string twice.
wstr.push_str(s);
assert_eq!(wstr.to_string().unwrap(), "MyStringMyString");
Sourcepub fn push_os_str(&mut self, s: impl AsRef<OsStr>)
pub fn push_os_str(&mut self, s: impl AsRef<OsStr>)
Extends the string with the given string slice.
No checks are performed on the strings. It is possible to end up nul values inside the string, and it is up to the caller to determine if that is acceptable.
§Examples
use widestring::U32String;
let s = "MyString";
let mut wstr = U32String::from_str(s);
// Push the original to the end, repeating the string twice.
wstr.push_os_str(s);
assert_eq!(wstr.to_string().unwrap(), "MyStringMyString");
Sourcepub fn push_char(&mut self, c: char)
pub fn push_char(&mut self, c: char)
Appends the given char
encoded as UTF-32 to the end of this string.
Sourcepub fn pop_char(&mut self) -> Option<u32>
pub fn pop_char(&mut self) -> Option<u32>
Removes the last value from the string buffer and returns it.
This method assumes UTF-32 encoding.
Returns None
if this String is empty.
Sourcepub fn remove_char(&mut self, idx: usize) -> u32
pub fn remove_char(&mut self, idx: usize) -> u32
Removes a value from this string at a position and returns it.
This method assumes UTF-32 encoding.
This is an O(n) operation, as it requires copying every element in the buffer.
§Panics
Panics if idx
is larger than or equal to the string’s length.
Sourcepub fn insert_char(&mut self, idx: usize, c: char)
pub fn insert_char(&mut self, idx: usize, c: char)
Inserts a character encoded as UTF-32 into this string at a specified position.
This is an O(n) operation as it requires copying every element in the buffer.
§Panics
Panics if idx
is larger than the string’s length.
Trait Implementations
Source§impl AddAssign<&U32CStr> for U32String
impl AddAssign<&U32CStr> for U32String
Source§fn add_assign(&mut self, rhs: &U32CStr)
fn add_assign(&mut self, rhs: &U32CStr)
+=
operation. Read moreSource§impl AddAssign<&U32Str> for U32String
impl AddAssign<&U32Str> for U32String
Source§fn add_assign(&mut self, rhs: &U32Str)
fn add_assign(&mut self, rhs: &U32Str)
+=
operation. Read moreSource§impl AddAssign<&Utf32Str> for U32String
impl AddAssign<&Utf32Str> for U32String
Source§fn add_assign(&mut self, rhs: &Utf32Str)
fn add_assign(&mut self, rhs: &Utf32Str)
+=
operation. Read moreSource§impl AddAssign<&str> for U32String
impl AddAssign<&str> for U32String
Source§fn add_assign(&mut self, rhs: &str)
fn add_assign(&mut self, rhs: &str)
+=
operation. Read moreSource§impl BorrowMut<U32Str> for U32String
impl BorrowMut<U32Str> for U32String
Source§fn borrow_mut(&mut self) -> &mut U32Str
fn borrow_mut(&mut self) -> &mut U32Str
Source§impl<'a> Extend<&'a U32CStr> for U32String
impl<'a> Extend<&'a U32CStr> for U32String
Source§fn extend<T: IntoIterator<Item = &'a U32CStr>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = &'a U32CStr>>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Source§impl<'a> Extend<&'a U32Str> for U32String
impl<'a> Extend<&'a U32Str> for U32String
Source§fn extend<T: IntoIterator<Item = &'a U32Str>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = &'a U32Str>>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Source§impl<'a> Extend<&'a Utf32Str> for U32String
impl<'a> Extend<&'a Utf32Str> for U32String
Source§fn extend<T: IntoIterator<Item = &'a Utf32Str>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = &'a Utf32Str>>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Source§impl<'a> Extend<&'a char> for U32String
impl<'a> Extend<&'a char> for U32String
Source§fn extend<T: IntoIterator<Item = &'a char>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = &'a char>>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Source§impl<'a> Extend<&'a str> for U32String
impl<'a> Extend<&'a str> for U32String
Source§fn extend<T: IntoIterator<Item = &'a str>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = &'a str>>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Source§impl Extend<Box<U32Str>> for U32String
impl Extend<Box<U32Str>> for U32String
Source§fn extend<T: IntoIterator<Item = Box<U32Str>>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = Box<U32Str>>>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Source§impl<'a> Extend<Cow<'a, U32Str>> for U32String
impl<'a> Extend<Cow<'a, U32Str>> for U32String
Source§fn extend<T: IntoIterator<Item = Cow<'a, U32Str>>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = Cow<'a, U32Str>>>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Source§impl Extend<String> for U32String
impl Extend<String> for U32String
Source§fn extend<T: IntoIterator<Item = String>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = String>>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Source§impl Extend<U32CString> for U32String
impl Extend<U32CString> for U32String
Source§fn extend<T: IntoIterator<Item = U32CString>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = U32CString>>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Source§impl Extend<U32String> for U32String
impl Extend<U32String> for U32String
Source§fn extend<T: IntoIterator<Item = U32String>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = U32String>>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Source§impl Extend<Utf32String> for U32String
impl Extend<Utf32String> for U32String
Source§fn extend<T: IntoIterator<Item = Utf32String>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = Utf32String>>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Source§impl Extend<char> for U32String
impl Extend<char> for U32String
Source§fn extend<T: IntoIterator<Item = char>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = char>>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)