Trait encode_unicode::CharExt [] [src]

pub trait CharExt: Sized {
    fn to_utf8(self) -> Utf8Char;
    fn to_utf16(self) -> Utf16Char;
    fn iter_utf8_bytes(self) -> Utf8Iterator;
    fn iter_utf16_units(self) -> Utf16Iterator;
    fn to_utf8_array(self) -> ([u8; 4], usize);
    fn to_utf16_tuple(self) -> (u16, Option<u16>);
    fn from_utf8_slice_start(src: &[u8])
                             -> Result<(Self, usize), InvalidUtf8Slice>; fn from_utf16_slice_start(src: &[u16])
                              -> Result<(Self, usize), InvalidUtf16Slice>; fn from_utf8_array(utf8: [u8; 4]) -> Result<Self, InvalidUtf8Array>; fn from_utf16_tuple(utf16: (u16, Option<u16>))
                        -> Result<Self, InvalidUtf16Tuple>; unsafe fn from_utf8_exact_slice_unchecked(src: &[u8]) -> Self; unsafe fn from_utf16_tuple_unchecked(utf16: (u16, Option<u16>)) -> Self; fn from_u32_detailed(c: u32) -> Result<Self, InvalidCodepoint>; }

Extension trait for char that adds methods for converting to and from UTF-8 or UTF-16.

Required Methods

Get the UTF-8 representation of this codepoint.

Utf8Char is to [u8;4] what char is to u32: a restricted type that cannot be mutated internally.

Get the UTF-16 representation of this codepoint.

Utf16Char is to [u16;2] what char is to u32: a restricted type that cannot be mutated internally.

Iterate over or read the one to four bytes in the UTF-8 representation of this codepoint.

An identical alternative to the unstable char.encode_utf8(). That method somehow still exist on stable, so I have to use a different name.

Iterate over the one or two units in the UTF-16 representation of this codepoint.

An identical alternative to the unstable char.encode_utf16(). That method somehow still exist on stable, so I have to use a different name.

Convert this char to an UTF-8 array and lenght,

The returned array is left-aligned with unused bytes set to zero, and the usize is how many bytes are used.

Convert this char to UTF-16. The second u16 is Some if a surrogate pair is required.

Create a char from the start of a UTF-8 slice, and also return how many bytes were used.

Create a char from the start of a UTF-16 slice, and also return how many units were used.

Convert an UTF-8 sequence as returned from .to_utf8_array() into a char

Convert a UTF-16 pair as returned from .to_utf16_tuple() into a char.

Convert an UTF-8 sequence into a char. The length of the slice is the length of the sequence, should be 1,2,3 or 4.

Panics

If the slice is empty

Convert a UTF-16 tuple as returned from .to_utf16_tuple() into a char.

Perform some extra validations compared to char::from_u32_unchecked()

Errors

This function will return an error if * the value is greater than 0x10ffff * the value is between 0xd800 and 0xdfff (inclusive)

Implementors