pub struct Utf16String { /* private fields */ }
Available on crate feature alloc only.
Expand description

A UTF-16 encoded, growable owned string.

Utf16String is a version of String that uses UTF-16 encoding instead of UTF-8 encoding. The equivalent of str for Utf16String is Utf16Str.

Unlike U16String which does not specify a coding, Utf16String is always valid UTF-16 encoding. Using unsafe methods to construct a Utf16String with invalid UTF-16 encoding results in undefined behavior.

§UTF-16

Utf16String is always UTF-16. This means if you need non-UTF-16 wide strings, you should use U16String instead. It is similar, but does not constrain the encoding.

This also means you cannot directly index a single element of the string, as UTF-16 encoding may be a single u16 value or a pair of u16 surrogates. Instead, you can index subslices of the string, or use the chars iterator instead.

§Examples

The easiest way to use Utf16String is with the utf16str! macro to convert string literals into UTF-16 string slices at compile time:

use widestring::{Utf16String, utf16str};
let hello = Utf16String::from(utf16str!("Hello, world!"));

Because this string is always valid UTF-16, it is a non-fallible, lossless conversion to and from standard Rust strings:

use widestring::Utf16String;
// Unlike the utf16str macro, this will do conversion at runtime instead of compile time
let hello = Utf16String::from_str("Hello, world!");
let hello_string: String = hello.to_string();
assert_eq!(hello, hello_string); // Can easily compare between string types

Implementations§

source§

impl Utf16String

source

pub const fn new() -> Self

Creates a new empty string.

Given that the string is empty, this will not allocate any initial buffer. While that means this initial operation is very inexpensive, it may cause excessive allocations later when you add data. If you have an idea of how much data the string will hold, consider with_capacity instead to prevent excessive re-allocation.

source

pub fn with_capacity(capacity: usize) -> Self

Creates a new empty string with a particular capacity.

This string has an internal buffer to hold its data. The capacity is the length of that buffer, and can be queried with the capacity method. This method creates and empty string, but one with an initial buffer that can hold capacity elements. This is useful when you may be appending a bunch of data to the string, reducing the number of reallocations it needs to do.

If the given capacity is 0, no allocation will occur, and this method is identical to the new method.

source

pub unsafe fn from_vec_unchecked(v: impl Into<Vec<u16>>) -> Self

Converts a u16 vector to a string without checking that the string contains valid UTF-16.

See the safe version, from_vec, for more information.

§Safety

This function is unsafe because it does not check that the vector passed to it is valid UTF-16. If this constraint is violated, undefined behavior results as it is assumed the Utf16String is always valid UTF-16.

§Examples
use widestring::Utf16String;

let sparkle_heart = vec![0xd83d, 0xdc96]; // Raw surrogate pair
let sparkle_heart = unsafe { Utf16String::from_vec_unchecked(sparkle_heart) };

assert_eq!("💖", sparkle_heart);
source

pub fn from_str<S: AsRef<str> + ?Sized>(s: &S) -> Self

Re-encodes a UTF-8–encoded string slice into a UTF-16–encoded string.

This operation is lossless and infallible, but requires a memory allocation.

§Examples
use widestring::Utf16String;
let music = Utf16String::from_str("𝄞music");
assert_eq!(utf16str!("𝄞music"), music);
source

pub fn as_utfstr(&self) -> &Utf16Str

Converts a string into a string slice.

source

pub fn as_mut_utfstr(&mut self) -> &mut Utf16Str

Converts a string into a mutable string slice.

source

pub fn as_ustr(&self) -> &U16Str

Converts this string into a wide string of undefined encoding.

source

pub fn into_vec(self) -> Vec<u16>

Converts a string into a vector of its elements.

This consumes the string without copying its contents.

source

pub fn push_utfstr<S: AsRef<Utf16Str> + ?Sized>(&mut self, string: &S)

Appends a given string slice onto the end of this string.

§Examples
use widestring::Utf16String;
let mut s = Utf16String::from_str("foo");
s.push_utfstr(utf16str!("bar"));
assert_eq!(utf16str!("foobar"), s);
source

pub fn capacity(&self) -> usize

Returns this string’s capacity, in number of elements.

source

pub fn reserve(&mut self, additional: usize)

Ensures that this string’s capacity is at least additional elements larger than its length.

The capacity may be increased by more than additional elements if it chooses, to prevent frequent reallocations.

If you do not want this “at least” behavior, see the reserve_exact method.

§Panics

Panics if the new capacity overflows usize.

source

pub fn reserve_exact(&mut self, additional: usize)

Ensures that this string’s capacity is additional elements larger than its length.

Consider using the reserve method unless you absolutely know better than the allocator.

§Panics

Panics if the new capacity overflows usize.

source

pub fn shrink_to_fit(&mut self)

Shrinks the capacity of this string to match its length.

source

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.

source

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

Returns a slice of this string’s contents.

source

pub unsafe fn as_mut_vec(&mut self) -> &mut Vec<u16>

Returns a mutable reference to the contents of this string.

§Safety

This function is unsafe because it does not check that the values in the vector are valid UTF-16. If this constraint is violated, it may cause undefined beahvior with future users of the string, as it is assumed that this string is always valid UTF-16.

source

pub fn len(&self) -> usize

Returns the length of this string in number of elements, not chars or graphemes.

In other words, it might not be what a human considers the length of the string.

source

pub fn is_empty(&self) -> bool

Returns true if this string has a length of zero, and false otherwise.

source

pub fn clear(&mut self)

Truncates the string, removing all contents.

While this means the string will have a length of zero, it does not touch its capacity.

source

pub fn into_boxed_utfstr(self) -> Box<Utf16Str>

Converts this string into a boxed string slice.

This will drop excess capacity.

source

pub fn push_str<S: AsRef<str> + ?Sized>(&mut self, string: &S)

Appends a given UTF-8 string slice onto the end of this string, converting it to UTF-16.

source§

impl Utf16String

source

pub fn from_vec(v: impl Into<Vec<u16>>) -> Result<Self, Utf16Error>

Converts a u16 vector of UTF-16 data to a string.

Not all slices of u16 values are valid to convert, since Utf16String requires that it is always valid UTF-16. This function checks to ensure that the values are valid UTF-16, and then does the conversion. This does not do any copying.

If you are sure that the slice is valid UTF-16, and you don’t want to incur the overhead of the validity check, there is an unsafe version of this function, from_vec_unchecked, which has the same behavior but skips the check.

If you need a string slice, consider using Utf16Str::from_slice instead.

The inverse of this method is into_vec.

§Errors

Returns an error if the vector is not UTF-16 with a description as to why the provided vector is not UTF-16. The error will contain the original Vec that can be reclaimed with into_vec.

§Examples
use widestring::Utf16String;

let sparkle_heart = vec![0xd83d, 0xdc96]; // Raw surrogate pair
let sparkle_heart = Utf16String::from_vec(sparkle_heart).unwrap();

assert_eq!("💖", sparkle_heart);

With incorrect values that return an error:

use widestring::Utf16String;

let sparkle_heart = vec![0xd83d, 0x0]; // This is an invalid unpaired surrogate

assert!(Utf16String::from_vec(sparkle_heart).is_err());
source

pub fn from_slice_lossy(s: &[u16]) -> Cow<'_, Utf16Str>

Converts a slice of u16 data to a string, including invalid characters.

Since the given u16 slice may not be valid UTF-16, and Utf16String requires that it is always valid UTF-16, during the conversion this function replaces any invalid UTF-16 sequences with U+FFFD REPLACEMENT CHARACTER, which looks like this: �

If you are sure that the slice is valid UTF-16, and you don’t want to incur the overhead of the conversion, there is an unsafe version of this function, from_vec_unchecked, which has the same behavior but skips the checks.

This function returns a Cow<'_, Utf16Str>. If the given slice is invalid UTF-16, then we need to insert our replacement characters which will change the size of the string, and hence, require an owned Utf16String. But if it’s already valid UTF-16, we don’t need a new allocation. This return type allows us to handle both cases.

§Examples
use widestring::Utf16String;

let sparkle_heart = vec![0xd83d, 0xdc96]; // Raw surrogate pair
let sparkle_heart = Utf16String::from_slice_lossy(&sparkle_heart);

assert_eq!(utf16str!("💖"), sparkle_heart);

With incorrect values that return an error:

use widestring::Utf16String;

let sparkle_heart = vec![0xd83d, 0x0]; // This is an invalid unpaired surrogate
let sparkle_heart = Utf16String::from_slice_lossy(&sparkle_heart);

assert_eq!(utf16str!("\u{fffd}\u{0000}"), sparkle_heart);
source

pub unsafe fn from_ustring_unchecked(s: impl Into<U16String>) -> Self

Converts a wide string of undefined encoding to a UTF-16 string without checking that the string contains valid UTF-16.

See the safe version, from_ustring, for more information.

§Safety

This function is unsafe because it does not check that the string passed to it is valid UTF-16. If this constraint is violated, undefined behavior results as it is assumed the Utf16String is always valid UTF-16.

§Examples
use widestring::{U16String, Utf16String};

let sparkle_heart = vec![0xd83d, 0xdc96]; // Raw surrogate pair
let sparkle_heart = U16String::from_vec(sparkle_heart);
let sparkle_heart = unsafe { Utf16String::from_ustring_unchecked(sparkle_heart) };

assert_eq!("💖", sparkle_heart);
source

pub fn from_ustring(s: impl Into<U16String>) -> Result<Self, Utf16Error>

Converts a wide string of undefined encoding into a UTF-16 string.

Not all strings with undefined encoding are valid to convert, since Utf16String requires that it is always valid UTF-16. This function checks to ensure that the string is valid UTF-16, and then does the conversion. This does not do any copying.

If you are sure that the string is valid UTF-16, and you don’t want to incur the overhead of the validity check, there is an unsafe version of this function, from_ustring_unchecked, which has the same behavior but skips the check.

If you need a string slice, consider using Utf16Str::from_ustr instead.

§Errors

Returns an error if the string is not UTF-16 with a description as to why the provided string is not UTF-16.

§Examples
use widestring::{U16String, Utf16String};

let sparkle_heart = vec![0xd83d, 0xdc96]; // Raw surrogate pair
let sparkle_heart = U16String::from_vec(sparkle_heart);
let sparkle_heart = Utf16String::from_ustring(sparkle_heart).unwrap();

assert_eq!("💖", sparkle_heart);

With incorrect values that return an error:

use widestring::{U16String, Utf16String};

let sparkle_heart = vec![0xd83d, 0x0]; // This is an invalid unpaired surrogate
let sparkle_heart = U16String::from_vec(sparkle_heart); // Valid for a U16String

assert!(Utf16String::from_ustring(sparkle_heart).is_err()); // But not for a Utf16String
source

pub fn from_ustr_lossy(s: &U16Str) -> Cow<'_, Utf16Str>

Converts a wide string slice of undefined encoding of to a UTF-16 string, including invalid characters.

Since the given string slice may not be valid UTF-16, and Utf16String requires that it is always valid UTF-16, during the conversion this function replaces any invalid UTF-16 sequences with U+FFFD REPLACEMENT CHARACTER, which looks like this: �

If you are sure that the slice is valid UTF-16, and you don’t want to incur the overhead of the conversion, there is an unsafe version of this function, from_ustring_unchecked, which has the same behavior but skips the checks.

This function returns a Cow<'_, Utf16Str>. If the given slice is invalid UTF-16, then we need to insert our replacement characters which will change the size of the string, and hence, require an owned Utf16String. But if it’s already valid UTF-16, we don’t need a new allocation. This return type allows us to handle both cases.

§Examples
use widestring::{U16Str, Utf16String};

let sparkle_heart = vec![0xd83d, 0xdc96]; // Raw surrogate pair
let sparkle_heart = U16Str::from_slice(&sparkle_heart);
let sparkle_heart = Utf16String::from_ustr_lossy(sparkle_heart);

assert_eq!(utf16str!("💖"), sparkle_heart);

With incorrect values that return an error:

use widestring::{U16Str, Utf16String};

let sparkle_heart = vec![0xd83d, 0x0]; // This is an invalid unpaired surrogate
let sparkle_heart = U16Str::from_slice(&sparkle_heart);
let sparkle_heart = Utf16String::from_ustr_lossy(sparkle_heart);

assert_eq!(utf16str!("\u{fffd}\u{0000}"), sparkle_heart);
source

pub unsafe fn from_ucstring_unchecked(s: impl Into<U16CString>) -> Self

Converts a wide C string to a UTF-16 string without checking that the string contains valid UTF-16.

The resulting string does not contain the nul terminator.

See the safe version, from_ucstring, for more information.

§Safety

This function is unsafe because it does not check that the string passed to it is valid UTF-16. If this constraint is violated, undefined behavior results as it is assumed the Utf16String is always valid UTF-16.

§Examples
use widestring::{U16CString, Utf16String};

let sparkle_heart = vec![0xd83d, 0xdc96]; // Raw surrogate pair
let sparkle_heart = U16CString::from_vec(sparkle_heart).unwrap();
let sparkle_heart = unsafe { Utf16String::from_ucstring_unchecked(sparkle_heart) };

assert_eq!("💖", sparkle_heart);
source

pub fn from_ucstring(s: impl Into<U16CString>) -> Result<Self, Utf16Error>

Converts a wide C string into a UTF-16 string.

The resulting string does not contain the nul terminator.

Not all wide C strings are valid to convert, since Utf16String requires that it is always valid UTF-16. This function checks to ensure that the string is valid UTF-16, and then does the conversion. This does not do any copying.

If you are sure that the string is valid UTF-16, and you don’t want to incur the overhead of the validity check, there is an unsafe version of this function, from_ucstring_unchecked, which has the same behavior but skips the check.

If you need a string slice, consider using Utf16Str::from_ucstr instead.

§Errors

Returns an error if the string is not UTF-16 with a description as to why the provided string is not UTF-16.

§Examples
use widestring::{U16CString, Utf16String};

let sparkle_heart = vec![0xd83d, 0xdc96]; // Raw surrogate pair
let sparkle_heart = U16CString::from_vec(sparkle_heart).unwrap();
let sparkle_heart = Utf16String::from_ucstring(sparkle_heart).unwrap();

assert_eq!("💖", sparkle_heart);

With incorrect values that return an error:

use widestring::{U16CString, Utf16String};

let sparkle_heart = vec![0xd83d]; // This is an invalid unpaired surrogate
let sparkle_heart = U16CString::from_vec(sparkle_heart).unwrap(); // Valid for a U16CString

assert!(Utf16String::from_ucstring(sparkle_heart).is_err()); // But not for a Utf16String
source

pub fn from_ucstr_lossy(s: &U16CStr) -> Cow<'_, Utf16Str>

Converts a wide C string slice of to a UTF-16 string, including invalid characters.

The resulting string does not contain the nul terminator.

Since the given string slice may not be valid UTF-16, and Utf16String requires that it is always valid UTF-16, during the conversion this function replaces any invalid UTF-16 sequences with U+FFFD REPLACEMENT CHARACTER, which looks like this: �

If you are sure that the slice is valid UTF-16, and you don’t want to incur the overhead of the conversion, there is an unsafe version of this function, from_ucstring_unchecked, which has the same behavior but skips the checks.

This function returns a Cow<'_, Utf16Str>. If the given slice is invalid UTF-16, then we need to insert our replacement characters which will change the size of the string, and hence, require an owned Utf16String. But if it’s already valid UTF-16, we don’t need a new allocation. This return type allows us to handle both cases.

§Examples
use widestring::{U16CStr, Utf16String};

let sparkle_heart = vec![0xd83d, 0xdc96, 0x0]; // Raw surrogate pair
let sparkle_heart = U16CStr::from_slice(&sparkle_heart).unwrap();
let sparkle_heart = Utf16String::from_ucstr_lossy(sparkle_heart);

assert_eq!(utf16str!("💖"), sparkle_heart);

With incorrect values that return an error:

use widestring::{U16CStr, Utf16String};

let sparkle_heart = vec![0xd83d, 0x0]; // This is an invalid unpaired surrogate
let sparkle_heart = U16CStr::from_slice(&sparkle_heart).unwrap();
let sparkle_heart = Utf16String::from_ucstr_lossy(sparkle_heart);

assert_eq!(utf16str!("\u{fffd}"), sparkle_heart);
source

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

Appends the given char to the end of this string.

§Examples
use widestring::Utf16String;
let mut s = Utf16String::from_str("abc");

s.push('1');
s.push('2');
s.push('3');

assert_eq!("abc123", s);
source

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.

§Panics

Panics if new_len does not lie on a char boundary.

§Examples
use widestring::Utf16String;
let mut s = Utf16String::from_str("hello");
s.truncate(2);
assert_eq!("he", s);
source

pub fn pop(&mut self) -> Option<char>

Removes the last character from the string buffer and returns it.

Returns None if this string is empty.

§Examples
use widestring::Utf16String;
let mut s = Utf16String::from_str("foo𝄞");

assert_eq!(s.pop(), Some('𝄞'));
assert_eq!(s.pop(), Some('o'));
assert_eq!(s.pop(), Some('o'));
assert_eq!(s.pop(), Some('f'));

assert_eq!(s.pop(), None);
source

pub fn remove(&mut self, idx: usize) -> char

Removes a char from this string at an offset and returns it.

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, or if it does not lie on a char boundary.

§Examples
use widestring::Utf16String;
let mut s = Utf16String::from_str("𝄞foo");

assert_eq!(s.remove(0), '𝄞');
assert_eq!(s.remove(1), 'o');
assert_eq!(s.remove(0), 'f');
assert_eq!(s.remove(0), 'o');
source

pub fn retain<F>(&mut self, f: F)
where F: FnMut(char) -> bool,

Retains only the characters specified by the predicate.

In other words, remove all characters c such that f(c) returns false. This method operates in place, visiting each character exactly once in the original order, and preserves the order of the retained characters.

§Examples
use widestring::Utf16String;
let mut s = Utf16String::from_str("f_o_ob_ar");

s.retain(|c| c != '_');

assert_eq!(s, "foobar");

Because the elements are visited exactly once in the original order, external state may be used to decide which elements to keep.

use widestring::Utf16String;
let mut s = Utf16String::from_str("abcde");
let keep = [false, true, true, false, true];
let mut iter = keep.iter();
s.retain(|_| *iter.next().unwrap());
assert_eq!(s, "bce");
source

pub fn insert(&mut self, idx: usize, ch: char)

Inserts a character into this string at an offset.

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, or if it does not lie on a char boundary.

§Examples
use widestring::Utf16String;
let mut s = Utf16String::with_capacity(5);

s.insert(0, '𝄞');
s.insert(0, 'f');
s.insert(1, 'o');
s.insert(4, 'o');

assert_eq!("fo𝄞o", s);
source

pub fn insert_utfstr(&mut self, idx: usize, string: &Utf16Str)

Inserts a UTF-16 string slice into this string at an offset.

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, or if it does not lie on a char boundary.

§Examples
use widestring::Utf16String;
let mut s = Utf16String::from_str("bar");

s.insert_utfstr(0, utf16str!("foo"));

assert_eq!("foobar", s);
source

pub fn split_off(&mut self, at: usize) -> Self

Splits the string into two at the given index.

Returns a newly allocated string. self contains elements [0, at), and the returned string contains elements [at, len). at must be on the boundary of a UTF-16 code point.

Note that the capacity of self does not change.

§Panics

Panics if at is not on a UTF-16 code point boundary, or if it is beyond the last code point of the string.

§Examples
use widestring::Utf16String;
let mut hello = Utf16String::from_str("Hello, World!");
let world = hello.split_off(7);
assert_eq!(hello, "Hello, ");
assert_eq!(world, "World!");
source

pub fn drain<R>(&mut self, range: R) -> DrainUtf16<'_>
where R: RangeBounds<usize>,

Creates a draining iterator that removes the specified range in the string and yields the removed chars.

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 do not lie on a char boundary, or if they’re out of bounds.

§Examples

Basic usage:

use widestring::Utf16String;
let mut s = Utf16String::from_str("α is alpha, β is beta");
let beta_offset = 12;

// Remove the range up until the β from the string
let t: Utf16String = s.drain(..beta_offset).collect();
assert_eq!(t, "α is alpha, ");
assert_eq!(s, "β is beta");

// A full range clears the string
s.drain(..);
assert_eq!(s, "");
source

pub fn replace_range<R>(&mut self, range: R, replace_with: &Utf16Str)
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 do not lie on a char boundary, or if they’re out of bounds.

§Examples

Basic usage:

use widestring::{utf16str, Utf16String};
let mut s = Utf16String::from_str("α is alpha, β is beta");
let beta_offset = 12;

// Replace the range up until the β from the string
s.replace_range(..beta_offset, utf16str!("Α is capital alpha; "));
assert_eq!(s, "Α is capital alpha; β is beta");

Methods from Deref<Target = Utf16Str>§

source

pub unsafe fn get_unchecked<I>(&self, index: I) -> &Self
where I: SliceIndex<[u16], Output = [u16]>,

Returns an unchecked subslice of this string slice.

This is the unchecked alternative to indexing the string slice.

§Safety

Callers of this function are responsible that these preconditions are satisfied:

  • The starting index must not exceed the ending index;
  • Indexes must be within bounds of the original slice;
  • Indexes must lie on UTF-16 sequence boundaries.

Failing that, the returned string slice may reference invalid memory or violate the invariants communicated by the type.

§Examples
let v = utf16str!("⚧️🏳️‍⚧️➡️s");
unsafe {
    assert_eq!(utf16str!("⚧️"), v.get_unchecked(..2));
    assert_eq!(utf16str!("🏳️‍⚧️"), v.get_unchecked(2..8));
    assert_eq!(utf16str!("➡️"), v.get_unchecked(8..10));
    assert_eq!(utf16str!("s"), v.get_unchecked(10..));
}
source

pub unsafe fn get_unchecked_mut<I>(&mut self, index: I) -> &mut Self
where I: SliceIndex<[u16], Output = [u16]>,

Returns a mutable, unchecked subslice of this string slice

This is the unchecked alternative to indexing the string slice.

§Safety

Callers of this function are responsible that these preconditions are satisfied:

  • The starting index must not exceed the ending index;
  • Indexes must be within bounds of the original slice;
  • Indexes must lie on UTF-16 sequence boundaries.

Failing that, the returned string slice may reference invalid memory or violate the invariants communicated by the type.

§Examples
let mut v = utf16str!("⚧️🏳️‍⚧️➡️s").to_owned();
unsafe {
    assert_eq!(utf16str!("⚧️"), v.get_unchecked_mut(..2));
    assert_eq!(utf16str!("🏳️‍⚧️"), v.get_unchecked_mut(2..8));
    assert_eq!(utf16str!("➡️"), v.get_unchecked_mut(8..10));
    assert_eq!(utf16str!("s"), v.get_unchecked_mut(10..));
}
source

pub fn len(&self) -> usize

Returns the length of self.

This length is in u16 values, not chars or graphemes. In other words, it may not be what human considers the length of the string.

§Examples
assert_eq!(utf16str!("foo").len(), 3);

let complex = utf16str!("⚧️🏳️‍⚧️➡️s");
assert_eq!(complex.len(), 11);
assert_eq!(complex.chars().count(), 10);
source

pub fn is_empty(&self) -> bool

Returns true if the string has a length of zero.

source

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

Converts a string to a slice of its underlying elements.

To convert the slice back into a string slice, use the from_slice function.

source

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

Converts a mutable string to a mutable slice of its underlying elements.

§Safety

This function is unsafe because you can violate the invariants of this type when mutating the slice. The caller must ensure that the contents of the slice is valid UTF before the borrow ends and the underlying string is used.

Use of this string type whose contents have been mutated to invalid UTF is undefined behavior.

source

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

Converts a string slice to a raw pointer.

This pointer will be pointing to the first element of the string slice.

The caller must ensure that the returned pointer is never written to. If you need to mutate the contents of the string slice, use as_mut_ptr.

source

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

Converts a mutable string slice to a mutable pointer.

This pointer will be pointing to the first element of the string slice.

source

pub fn as_ustr(&self) -> &U16Str

Returns this string as a wide string slice of undefined encoding.

source

pub fn trim(&self) -> &Self

Returns a string slice with leading and trailing whitespace removed.

‘Whitespace’ is defined according to the terms of the Unicode Derived Core Property White_Space.

source

pub fn trim_start(&self) -> &Self

Returns a string slice with leading whitespace removed.

‘Whitespace’ is defined according to the terms of the Unicode Derived Core Property White_Space.

§Text directionality

A string is a sequence of elements. start in this context means the first position of that sequence; for a left-to-right language like English or Russian, this will be left side, and for right-to-left languages like Arabic or Hebrew, this will be the right side.

source

pub fn trim_end(&self) -> &Self

Returns a string slice with trailing whitespace removed.

‘Whitespace’ is defined according to the terms of the Unicode Derived Core Property White_Space.

§Text directionality

A string is a sequence of elements. end in this context means the last position of that sequence; for a left-to-right language like English or Russian, this will be right side, and for right-to-left languages like Arabic or Hebrew, this will be the left side.

source

pub fn repeat(&self, n: usize) -> Utf16String

Creates a new owned string by repeating this string n times.

§Panics

This function will panic if the capacity would overflow.

source

pub fn to_string(&self) -> String

Converts to a standard UTF-8 String.

Because this string is always valid UTF-16, the conversion is lossless and non-fallible.

source

pub fn is_char_boundary(&self, index: usize) -> bool

Checks that index-th value is the value in a UTF-16 code point sequence or the end of the string.

Returns true if the value at index is not a UTF-16 surrogate value, or if the value at index is the first value of a surrogate pair (the “high” surrogate). Returns false if the value at index is the second value of a surrogate pair (a.k.a the “low” surrogate).

The start and end of the string (when index == self.len()) are considered to be boundaries.

Returns false if index is greater than self.len()`.

§Examples
let s = utf16str!("Sparkle 💖 Heart");
assert!(s.is_char_boundary(0));

// high surrogate of `💖`
assert!(s.is_char_boundary(8));
// low surrogate of `💖`
assert!(!s.is_char_boundary(9));

assert!(s.is_char_boundary(s.len()));
source

pub fn get<I>(&self, index: I) -> Option<&Self>
where I: RangeBounds<usize> + SliceIndex<[u16], Output = [u16]>,

Returns a subslice of this string.

This is the non-panicking alternative to indexing the string. Returns None whenever equivalent indexing operation would panic.

§Examples
let v = utf16str!("⚧️🏳️‍⚧️➡️s");

assert_eq!(Some(utf16str!("⚧️")), v.get(..2));
assert_eq!(Some(utf16str!("🏳️‍⚧️")), v.get(2..8));
assert_eq!(Some(utf16str!("➡️")), v.get(8..10));
assert_eq!(Some(utf16str!("s")), v.get(10..));

assert!(v.get(3..4).is_none());
source

pub fn get_mut<I>(&mut self, index: I) -> Option<&mut Self>
where I: RangeBounds<usize> + SliceIndex<[u16], Output = [u16]>,

Returns a mutable subslice of this string.

This is the non-panicking alternative to indexing the string. Returns None whenever equivalent indexing operation would panic.

§Examples
let mut v = utf16str!("⚧️🏳️‍⚧️➡️s").to_owned();

assert_eq!(utf16str!("⚧️"), v.get_mut(..2).unwrap());
assert_eq!(utf16str!("🏳️‍⚧️"), v.get_mut(2..8).unwrap());
assert_eq!(utf16str!("➡️"), v.get_mut(8..10).unwrap());
assert_eq!(utf16str!("s"), v.get_mut(10..).unwrap());

assert!(v.get_mut(3..4).is_none());
source

pub fn split_at(&self, mid: usize) -> (&Self, &Self)

Divide one string slice into two at an index.

The argument, mid, should be an offset from the start of the string. It must also be on the boundary of a UTF-16 code point.

The two slices returned go from the start of the string slice to mid, and from mid to the end of the string slice.

To get mutable string slices instead, see the split_at_mut method.

§Panics

Panics if mid is not on a UTF-16 code point boundary, or if it is past the end of the last code point of the string slice.

§Examples
let s = utf16str!("Per Martin-Löf");

let (first, last) = s.split_at(3);

assert_eq!("Per", first);
assert_eq!(" Martin-Löf", last);
source

pub fn split_at_mut(&mut self, mid: usize) -> (&mut Self, &mut Self)

Divide one mutable string slice into two at an index.

The argument, mid, should be an offset from the start of the string. It must also be on the boundary of a UTF-16 code point.

The two slices returned go from the start of the string slice to mid, and from mid to the end of the string slice.

To get immutable string slices instead, see the split_at method.

§Panics

Panics if mid is not on a UTF-16 code point boundary, or if it is past the end of the last code point of the string slice.

§Examples
let mut s = utf16str!("Per Martin-Löf").to_owned();

let (first, last) = s.split_at_mut(3);

assert_eq!("Per", first);
assert_eq!(" Martin-Löf", last);
source

pub fn chars(&self) -> CharsUtf16<'_>

Returns an iterator over the chars of a string slice.

As this string slice consists of valid UTF-16, we can iterate through a string slice by char. This method returns such an iterator.

It’s important to remember that char represents a Unicode Scalar Value, and might not match your idea of what a ‘character’ is. Iteration over grapheme clusters may be what you actually want. This functionality is not provided by this crate.

source

pub fn char_indices(&self) -> CharIndicesUtf16<'_>

Returns an iterator over the chars of a string slice and their positions.

As this string slice consists of valid UTF-16, we can iterate through a string slice by char. This method returns an iterator of both these chars as well as their offsets.

The iterator yields tuples. The position is first, the char is second.

source

pub fn code_units(&self) -> CodeUnits<'_>

An iterator over the u16 code units of a string slice.

As a UTF-16 string slice consists of a sequence of u16 code units, we can iterate through a string slice by each code unit. This method returns such an iterator.

source

pub fn encode_utf8(&self) -> EncodeUtf8<CharsUtf16<'_>>

Returns an iterator of bytes over the string encoded as UTF-8.

source

pub fn encode_utf32(&self) -> EncodeUtf32<CharsUtf16<'_>>

Returns an iterator of u32 over the sting encoded as UTF-32.

source

pub fn escape_debug(&self) -> EscapeDebug<CharsUtf16<'_>>

Returns an iterator that escapes each char in self with char::escape_debug.

source

pub fn escape_default(&self) -> EscapeDefault<CharsUtf16<'_>>

Returns an iterator that escapes each char in self with char::escape_default.

source

pub fn escape_unicode(&self) -> EscapeUnicode<CharsUtf16<'_>>

Returns an iterator that escapes each char in self with char::escape_unicode.

source

pub fn to_lowercase(&self) -> Utf16String

Returns the lowercase equivalent of this string slice, as a new Utf16String.

‘Lowercase’ is defined according to the terms of the Unicode Derived Core Property Lowercase.

Since some characters can expand into multiple characters when changing the case, this function returns a Utf16String instead of modifying the parameter in-place.

source

pub fn to_uppercase(&self) -> Utf16String

Returns the uppercase equivalent of this string slice, as a new Utf16String.

‘Uppercase’ is defined according to the terms of the Unicode Derived Core Property Uppercase.

Since some characters can expand into multiple characters when changing the case, this function returns a Utf16String instead of modifying the parameter in-place.

Trait Implementations§

source§

impl Add<&Utf16Str> for Utf16String

§

type Output = Utf16String

The resulting type after applying the + operator.
source§

fn add(self, rhs: &Utf16Str) -> Self::Output

Performs the + operation. Read more
source§

impl Add<&str> for Utf16String

§

type Output = Utf16String

The resulting type after applying the + operator.
source§

fn add(self, rhs: &str) -> Self::Output

Performs the + operation. Read more
source§

impl AddAssign<&Utf16Str> for Utf16String

source§

fn add_assign(&mut self, rhs: &Utf16Str)

Performs the += operation. Read more
source§

impl AddAssign<&str> for Utf16String

source§

fn add_assign(&mut self, rhs: &str)

Performs the += operation. Read more
source§

impl AsMut<Utf16Str> for Utf16String

source§

fn as_mut(&mut self) -> &mut Utf16Str

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl AsRef<[u16]> for Utf16String

source§

fn as_ref(&self) -> &[u16]

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl AsRef<U16Str> for Utf16String

source§

fn as_ref(&self) -> &U16Str

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl AsRef<Utf16Str> for Utf16String

source§

fn as_ref(&self) -> &Utf16Str

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Borrow<Utf16Str> for Utf16String

source§

fn borrow(&self) -> &Utf16Str

Immutably borrows from an owned value. Read more
source§

impl BorrowMut<Utf16Str> for Utf16String

source§

fn borrow_mut(&mut self) -> &mut Utf16Str

Mutably borrows from an owned value. Read more
source§

impl Clone for Utf16String

source§

fn clone(&self) -> Utf16String

Returns a copy 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 Debug for Utf16String

source§

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

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

impl Default for Utf16String

source§

fn default() -> Utf16String

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

impl Deref for Utf16String

§

type Target = Utf16Str

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl DerefMut for Utf16String

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
source§

impl Display for Utf16String

source§

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

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

impl<'a> Extend<&'a Utf16Str> for Utf16String

source§

fn extend<T: IntoIterator<Item = &'a Utf16Str>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl<'a> Extend<&'a char> for Utf16String

source§

fn extend<T: IntoIterator<Item = &'a char>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl<'a> Extend<&'a str> for Utf16String

source§

fn extend<T: IntoIterator<Item = &'a str>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl Extend<Box<Utf16Str>> for Utf16String

source§

fn extend<T: IntoIterator<Item = Box<Utf16Str>>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl<'a> Extend<Cow<'a, Utf16Str>> for Utf16String

source§

fn extend<T: IntoIterator<Item = Cow<'a, Utf16Str>>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl Extend<String> for Utf16String

source§

fn extend<T: IntoIterator<Item = String>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl Extend<Utf16String> for U16String

source§

fn extend<T: IntoIterator<Item = Utf16String>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl Extend<Utf16String> for Utf16String

source§

fn extend<T: IntoIterator<Item = Utf16String>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl Extend<char> for Utf16String

source§

fn extend<T: IntoIterator<Item = char>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl From<&Utf16Str> for Utf16String

source§

fn from(value: &Utf16Str) -> Self

Converts to this type from the input type.
source§

impl<'a> From<&'a Utf16String> for Cow<'a, Utf16Str>

source§

fn from(value: &'a Utf16String) -> Self

Converts to this type from the input type.
source§

impl From<&Utf16String> for Utf16String

source§

fn from(value: &Utf16String) -> Self

Converts to this type from the input type.
source§

impl From<&mut Utf16Str> for Utf16String

source§

fn from(value: &mut Utf16Str) -> Self

Converts to this type from the input type.
source§

impl From<&str> for Utf16String

source§

fn from(value: &str) -> Self

Converts to this type from the input type.
source§

impl From<Cow<'_, Utf16Str>> for Utf16String

source§

fn from(value: Cow<'_, Utf16Str>) -> Self

Converts to this type from the input type.
source§

impl From<String> for Utf16String

source§

fn from(value: String) -> Self

Converts to this type from the input type.
source§

impl From<Utf16String> for Cow<'_, Utf16Str>

source§

fn from(value: Utf16String) -> Self

Converts to this type from the input type.
source§

impl From<Utf16String> for OsString

source§

fn from(value: Utf16String) -> OsString

Converts to this type from the input type.
source§

impl From<Utf16String> for String

source§

fn from(value: Utf16String) -> Self

Converts to this type from the input type.
source§

impl From<Utf16String> for U16String

source§

fn from(value: Utf16String) -> Self

Converts to this type from the input type.
source§

impl<'a> FromIterator<&'a Utf16Str> for Utf16String

source§

fn from_iter<T: IntoIterator<Item = &'a Utf16Str>>(iter: T) -> Self

Creates a value from an iterator. Read more
source§

impl<'a> FromIterator<&'a char> for Utf16String

source§

fn from_iter<T: IntoIterator<Item = &'a char>>(iter: T) -> Self

Creates a value from an iterator. Read more
source§

impl<'a> FromIterator<&'a str> for Utf16String

source§

fn from_iter<T: IntoIterator<Item = &'a str>>(iter: T) -> Self

Creates a value from an iterator. Read more
source§

impl FromIterator<Box<Utf16Str>> for Utf16String

source§

fn from_iter<T: IntoIterator<Item = Box<Utf16Str>>>(iter: T) -> Self

Creates a value from an iterator. Read more
source§

impl<'a> FromIterator<Cow<'a, Utf16Str>> for Utf16String

source§

fn from_iter<T: IntoIterator<Item = Cow<'a, Utf16Str>>>(iter: T) -> Self

Creates a value from an iterator. Read more
source§

impl FromIterator<String> for Utf16String

source§

fn from_iter<T: IntoIterator<Item = String>>(iter: T) -> Self

Creates a value from an iterator. Read more
source§

impl FromIterator<Utf16String> for U16String

source§

fn from_iter<T: IntoIterator<Item = Utf16String>>(iter: T) -> Self

Creates a value from an iterator. Read more
source§

impl FromIterator<Utf16String> for Utf16String

source§

fn from_iter<T: IntoIterator<Item = Utf16String>>(iter: T) -> Self

Creates a value from an iterator. Read more
source§

impl FromIterator<char> for Utf16String

source§

fn from_iter<T: IntoIterator<Item = char>>(iter: T) -> Self

Creates a value from an iterator. Read more
source§

impl FromStr for Utf16String

§

type Err = Infallible

The associated error which can be returned from parsing.
source§

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

Parses a string s to return a value of this type. Read more
source§

impl Hash for Utf16String

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<I> Index<I> for Utf16String
where I: RangeBounds<usize> + SliceIndex<[u16], Output = [u16]>,

§

type Output = Utf16Str

The returned type after indexing.
source§

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

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

impl<I> IndexMut<I> for Utf16String
where I: RangeBounds<usize> + SliceIndex<[u16], Output = [u16]>,

source§

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

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

impl Ord for Utf16String

source§

fn cmp(&self, other: &Utf16String) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq<&Utf16Str> for Utf16String

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<&Utf32Str> for Utf16String

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<&str> for Utf16String

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<Cow<'_, Utf16Str>> for Utf16String

source§

fn eq(&self, other: &Cow<'_, Utf16Str>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<Cow<'_, str>> for Utf16String

source§

fn eq(&self, other: &Cow<'_, str>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<String> for Utf16String

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<U16CStr> for Utf16String

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<U16CString> for Utf16String

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<U16Str> for Utf16String

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<U16String> for Utf16String

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<Utf16Str> for Utf16String

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<Utf16String> for &Utf16Str

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<Utf16String> for &Utf32Str

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<Utf16String> for &str

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<Utf16String> for Cow<'_, Utf16Str>

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<Utf16String> for Cow<'_, str>

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<Utf16String> for String

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<Utf16String> for U16CStr

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<Utf16String> for U16CString

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<Utf16String> for U16Str

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<Utf16String> for U16String

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<Utf16String> for Utf16Str

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<Utf16String> for Utf32String

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<Utf16String> for str

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<Utf32String> for Utf16String

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<str> for Utf16String

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq for Utf16String

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Utf16String

source§

fn partial_cmp(&self, other: &Utf16String) -> 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

This method 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

This method 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

This method 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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl TryFrom<&[u16]> for Utf16String

§

type Error = Utf16Error

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

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

Performs the conversion.
source§

impl TryFrom<&U16CStr> for Utf16String

§

type Error = Utf16Error

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

fn try_from(value: &U16CStr) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<&U16Str> for Utf16String

§

type Error = Utf16Error

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

fn try_from(value: &U16Str) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<U16CString> for Utf16String

§

type Error = Utf16Error

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

fn try_from(value: U16CString) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<U16String> for Utf16String

§

type Error = Utf16Error

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

fn try_from(value: U16String) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Vec<u16>> for Utf16String

§

type Error = Utf16Error

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

fn try_from(value: Vec<u16>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl Write for Utf16String

source§

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

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

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

Writes a char 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
source§

impl Eq for Utf16String

source§

impl StructuralPartialEq for Utf16String

Auto Trait Implementations§

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

§

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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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.