[−][src]Struct encode_unicode::Utf16Char
An unicode codepoint stored as UTF-16.
It can be borrowed as an u16
slice, and has the same size as char
.
Methods
impl Utf16Char
[src]
pub fn from_str_start(s: &str) -> Result<(Self, usize), EmptyStrError>
[src]
Create an Utf16Char
from the first codepoint in a string slice,
converting from UTF-8 to UTF-16.
The returned usize
is the number of UTF-8 bytes used from the str,
and not the number of UTF-16 units.
Returns an error if the str
is empty.
Examples
use encode_unicode::Utf16Char; assert_eq!(Utf16Char::from_str_start("a"), Ok((Utf16Char::from('a'),1))); assert_eq!(Utf16Char::from_str_start("ab"), Ok((Utf16Char::from('a'),1))); assert_eq!(Utf16Char::from_str_start("🂠 "), Ok((Utf16Char::from('🂠'),4))); assert_eq!(Utf16Char::from_str_start("é"), Ok((Utf16Char::from('e'),1)));// 'e'+u301 combining mark assert!(Utf16Char::from_str_start("").is_err());
pub fn from_slice_start(src: &[u16]) -> Result<(Self, usize), InvalidUtf16Slice>
[src]
Validate and store the first UTF-16 codepoint in the slice. Also return how many units were needed.
pub unsafe fn from_slice_start_unchecked(src: &[u16]) -> (Self, usize)
[src]
Store the first UTF-16 codepoint of the slice.
Safety
The slice must be non-empty and start with a valid UTF-16 codepoint.
The length of the slice is never checked.
pub fn from_array(units: [u16; 2]) -> Result<Self, InvalidUtf16Array>
[src]
Validate and store an UTF-16 array as returned from char.to_utf16_array()
.
Examples
use encode_unicode::Utf16Char; use encode_unicode::error::InvalidUtf16Array; assert_eq!(Utf16Char::from_array(['x' as u16, 'y' as u16]), Ok(Utf16Char::from('x'))); assert_eq!(Utf16Char::from_array(['睷' as u16, 0]), Ok(Utf16Char::from('睷'))); assert_eq!(Utf16Char::from_array([0xda6f, 0xdcde]), Ok(Utf16Char::from('\u{abcde}'))); assert_eq!(Utf16Char::from_array([0xf111, 0xdbad]), Ok(Utf16Char::from('\u{f111}'))); assert_eq!(Utf16Char::from_array([0xdaaf, 0xdaaf]), Err(InvalidUtf16Array::SecondIsNotTrailingSurrogate)); assert_eq!(Utf16Char::from_array([0xdcac, 0x9000]), Err(InvalidUtf16Array::FirstIsTrailingSurrogate));
pub unsafe fn from_array_unchecked(units: [u16; 2]) -> Self
[src]
Create an Utf16Char
from an array as returned from char.to_utf16_array()
.
Safety
The units must form a valid codepoint, and the second unit must be 0
when a surrogate pair is not required.
Violating this can easily lead to undefined behavior, although unlike
char
bad Utf16Char
s simply existing is not immediately UB.
pub fn from_tuple(utf16: (u16, Option<u16>)) -> Result<Self, InvalidUtf16Tuple>
[src]
Validate and store a UTF-16 pair as returned from char.to_utf16_tuple()
.
pub unsafe fn from_tuple_unchecked(utf16: (u16, Option<u16>)) -> Self
[src]
Create an Utf16Char
from a tuple as returned from char.to_utf16_tuple()
.
Safety
The units must form a valid codepoint with the second being 0 when a surrogate pair is not required. Violating this can easily lead to undefined behavior.
pub fn from_bmp(bmp_codepoint: u16) -> Result<Self, NonBMPError>
[src]
Create an Utf16Char
from a single unit.
Codepoints < '\u{1_0000}' (which fit in a u16
) are part of the basic
multilingual plane unless they are reserved for surrogate pairs.
Errors
Returns NonBMPError
if the unit is in the range 0xd800..0xe000
(which means that it's part of a surrogat pair)
Examples
assert_eq!(Utf16Char::from_bmp(0x40).unwrap(), '@'); assert_eq!(Utf16Char::from_bmp('ø' as u16).unwrap(), 'ø'); assert!(Utf16Char::from_bmp(0xdddd).is_err());
pub unsafe fn from_bmp_unchecked(bmp_codepoint: u16) -> Self
[src]
Create an Utf16Char
from a single unit without checking that it's a
valid codepoint on its own.
Safety
The unit must be less than 0xd800 or greater than 0xdfff.
In other words, not part of a surrogate pair.
Violating this can easily lead to undefined behavior.
pub fn is_bmp(&self) -> bool
[src]
Checks that the codepoint is in the basic multilingual plane.
Examples
assert_eq!(Utf16Char::from('e').is_bmp(), true); assert_eq!(Utf16Char::from('€').is_bmp(), true); assert_eq!(Utf16Char::from('𝔼').is_bmp(), false);
pub fn len(self) -> usize
[src]
The number of units this character is made up of.
Is either 1 or 2 and identical to .as_char().len_utf16()
or .as_ref().len()
.
pub fn is_ascii(&self) -> bool
[src]
Checks that the codepoint is an ASCII character.
pub fn eq_ignore_ascii_case(&self, other: &Self) -> bool
[src]
Checks that two characters are an ASCII case-insensitive match.
Is equivalent to a.to_ascii_lowercase() == b.to_ascii_lowercase()
.
pub fn to_ascii_uppercase(&self) -> Self
[src]
Converts the character to its ASCII upper case equivalent.
ASCII letters 'a' to 'z' are mapped to 'A' to 'Z', but non-ASCII letters are unchanged.
pub fn to_ascii_lowercase(&self) -> Self
[src]
Converts the character to its ASCII lower case equivalent.
ASCII letters 'A' to 'Z' are mapped to 'a' to 'z', but non-ASCII letters are unchanged.
pub fn make_ascii_uppercase(&mut self)
[src]
Converts the character to its ASCII upper case equivalent in-place.
ASCII letters 'a' to 'z' are mapped to 'A' to 'Z', but non-ASCII letters are unchanged.
pub fn make_ascii_lowercase(&mut self)
[src]
Converts the character to its ASCII lower case equivalent in-place.
ASCII letters 'A' to 'Z' are mapped to 'a' to 'z', but non-ASCII letters are unchanged.
pub fn to_char(self) -> char
[src]
Convert from UTF-16 to UTF-32
pub fn to_slice(self, dst: &mut [u16]) -> usize
[src]
Write the internal representation to a slice,
and then returns the number of u16
s written.
Panics
Will panic the buffer is too small;
You can get the required length from .len()
,
but a buffer of length two is always large enough.
pub fn to_array(self) -> [u16; 2]
[src]
Get the character represented as an array of two units.
The second u16
is zero for codepoints that fit in one unit.
pub fn to_tuple(self) -> (u16, Option<u16>)
[src]
The second u16
is used for surrogate pairs.
Trait Implementations
impl From<Utf16Char> for Utf8Char
[src]
impl From<char> for Utf16Char
[src]
impl From<Utf8Char> for Utf16Char
[src]
impl From<Utf16Char> for char
[src]
impl From<AsciiChar> for Utf16Char
[src]
Requires the feature "ascii".
impl From<Utf16Char> for Utf16Iterator
[src]
impl Ord for Utf16Char
[src]
fn cmp(&self, rhs: &Self) -> Ordering
[src]
fn max(self, other: Self) -> Self
1.21.0[src]
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
Compares and returns the minimum of two values. Read more
fn clamp(self, min: Self, max: Self) -> Self
[src]
clamp
)Restrict a value to a certain interval. Read more
impl PartialOrd<Utf16Char> for Utf8Char
[src]
fn partial_cmp(&self, u16c: &Utf16Char) -> Option<Ordering>
[src]
#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl PartialOrd<Utf16Char> for Utf16Char
[src]
fn partial_cmp(&self, rhs: &Self) -> Option<Ordering>
[src]
#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl PartialOrd<char> for Utf16Char
[src]
fn partial_cmp(&self, u32c: &char) -> Option<Ordering>
[src]
#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl PartialOrd<Utf16Char> for char
[src]
fn partial_cmp(&self, u16c: &Utf16Char) -> Option<Ordering>
[src]
#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl PartialOrd<Utf8Char> for Utf16Char
[src]
fn partial_cmp(&self, u8c: &Utf8Char) -> Option<Ordering>
[src]
#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl PartialOrd<AsciiChar> for Utf16Char
[src]
Utf16Char
s that are not ASCII always compare greater.
fn partial_cmp(&self, ascii: &AsciiChar) -> Option<Ordering>
[src]
#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl PartialOrd<Utf16Char> for AsciiChar
[src]
Utf16Char
s that are not ASCII always compare greater.
fn partial_cmp(&self, u16c: &Utf16Char) -> Option<Ordering>
[src]
#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl PartialEq<Utf16Char> for Utf8Char
[src]
fn eq(&self, u16c: &Utf16Char) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl PartialEq<Utf16Char> for Utf16Char
[src]
impl PartialEq<char> for Utf16Char
[src]
fn eq(&self, u32c: &char) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl PartialEq<Utf16Char> for char
[src]
fn eq(&self, u16c: &Utf16Char) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl PartialEq<Utf8Char> for Utf16Char
[src]
fn eq(&self, u8c: &Utf8Char) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl PartialEq<u16> for Utf16Char
[src]
Only considers the unit equal if the codepoint of the Utf16Char
is not
made up of a surrogate pair.
There is no impl in the opposite direction, as this should only be used to
compare Utf16Char
s against constants.
Examples
assert!(Utf16Char::from('6') == b'6' as u16); assert!(Utf16Char::from('\u{FFFF}') == 0xffff_u16); assert!(Utf16Char::from_tuple((0xd876, Some(0xdef9))).unwrap() != 0xd876_u16);
fn eq(&self, unit: &u16) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl PartialEq<u8> for Utf16Char
[src]
Only considers the byte equal if the codepoint of the Utf16Char
is <= U+FF.
Examples
assert!(Utf16Char::from('6') == b'6'); assert!(Utf16Char::from('\u{00FF}') == b'\xff'); assert!(Utf16Char::from('\u{0100}') != b'\0');
fn eq(&self, byte: &u8) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl PartialEq<AsciiChar> for Utf16Char
[src]
Utf16Char
s that are not ASCII never compare equal.
fn eq(&self, ascii: &AsciiChar) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl PartialEq<Utf16Char> for AsciiChar
[src]
Utf16Char
s that are not ASCII never compare equal.
fn eq(&self, u16c: &Utf16Char) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl Default for Utf16Char
[src]
impl IntoIterator for Utf16Char
[src]
type Item = u16
The type of the elements being iterated over.
type IntoIter = Utf16Iterator
Which kind of iterator are we turning this into?
ⓘImportant traits for Utf16Iteratorfn into_iter(self) -> Utf16Iterator
[src]
Iterate over the units.
impl Extend<Utf16Char> for Vec<u16>
[src]
fn extend<I: IntoIterator<Item = Utf16Char>>(&mut self, iter: I)
[src]
impl<'a> Extend<&'a Utf16Char> for Vec<u16>
[src]
fn extend<I: IntoIterator<Item = &'a Utf16Char>>(&mut self, iter: I)
[src]
impl Extend<Utf16Char> for String
[src]
fn extend<I: IntoIterator<Item = Utf16Char>>(&mut self, iter: I)
[src]
impl<'a> Extend<&'a Utf16Char> for String
[src]
fn extend<I: IntoIterator<Item = &'a Utf16Char>>(&mut self, iter: I)
[src]
impl Clone for Utf16Char
[src]
fn clone(&self) -> Utf16Char
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Eq for Utf16Char
[src]
impl AsRef<[u16]> for Utf16Char
[src]
impl Copy for Utf16Char
[src]
impl Deref for Utf16Char
[src]
impl Display for Utf16Char
[src]
impl Debug for Utf16Char
[src]
impl FromStr for Utf16Char
[src]
type Err = FromStrError
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<Self, FromStrError>
[src]
Create an Utf16Char
from a string slice.
The string must contain exactly one codepoint.
Examples
use encode_unicode::error::FromStrError::*; use encode_unicode::Utf16Char; use std::str::FromStr; assert_eq!(Utf16Char::from_str("a"), Ok(Utf16Char::from('a'))); assert_eq!(Utf16Char::from_str("🂠"), Ok(Utf16Char::from('🂠'))); assert_eq!(Utf16Char::from_str(""), Err(Empty)); assert_eq!(Utf16Char::from_str("ab"), Err(MultipleCodepoints)); assert_eq!(Utf16Char::from_str("é"), Err(MultipleCodepoints));// 'e'+u301 combining mark
impl Hash for Utf16Char
[src]
fn hash<H: Hasher>(&self, state: &mut H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl FromIterator<Utf16Char> for Vec<u16>
[src]
fn from_iter<I: IntoIterator<Item = Utf16Char>>(iter: I) -> Self
[src]
impl<'a> FromIterator<&'a Utf16Char> for Vec<u16>
[src]
fn from_iter<I: IntoIterator<Item = &'a Utf16Char>>(iter: I) -> Self
[src]
impl FromIterator<Utf16Char> for String
[src]
fn from_iter<I: IntoIterator<Item = Utf16Char>>(iter: I) -> Self
[src]
impl<'a> FromIterator<&'a Utf16Char> for String
[src]
fn from_iter<I: IntoIterator<Item = &'a Utf16Char>>(iter: I) -> Self
[src]
impl Borrow<[u16]> for Utf16Char
[src]
impl AsciiExt for Utf16Char
[src]
type Owned = Self
use inherent methods instead
Container type for copied ASCII characters.
fn is_ascii(&self) -> bool
[src]
fn eq_ignore_ascii_case(&self, other: &Self) -> bool
[src]
fn to_ascii_uppercase(&self) -> Self
[src]
fn to_ascii_lowercase(&self) -> Self
[src]
fn make_ascii_uppercase(&mut self)
[src]
fn make_ascii_lowercase(&mut self)
[src]
impl ToAsciiChar for Utf16Char
[src]
Requires the feature "ascii".
fn to_ascii_char(self) -> Result<AsciiChar, ToAsciiCharError>
[src]
unsafe fn to_ascii_char_unchecked(self) -> AsciiChar
[src]
Auto Trait Implementations
impl Send for Utf16Char
impl Unpin for Utf16Char
impl Sync for Utf16Char
impl UnwindSafe for Utf16Char
impl RefUnwindSafe for Utf16Char
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<I> IntoIterator for I where
I: Iterator,
[src]
I: Iterator,
type Item = <I as Iterator>::Item
The type of the elements being iterated over.
type IntoIter = I
Which kind of iterator are we turning this into?
fn into_iter(self) -> I
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,