devela::all

Trait UnicodeScalar

Source
pub trait UnicodeScalar {
    const MIN: Self;
    const MAX: Self;
Show 21 methods // Required methods fn byte_len(self) -> usize ; fn len_utf8(self) -> usize ; fn len_utf16(self) -> usize ; fn encode_utf8(self, dst: &mut [u8]) -> &mut str ; fn to_utf8_bytes(self) -> [u8; 4]; fn encode_utf16(self, dst: &mut [u16]) -> &mut [u16] ; fn to_digit(self, radix: u32) -> Option<u32> ; fn to_ascii_uppercase(self) -> Self where Self: Sized; fn to_ascii_lowercase(self) -> Self where Self: Sized; fn is_noncharacter(self) -> bool; fn is_digit(self, radix: u32) -> bool; fn is_control(self) -> bool; fn is_nul(self) -> bool; fn is_alphabetic(self) -> bool; fn is_numeric(self) -> bool; fn is_alphanumeric(self) -> bool; fn is_lowercase(self) -> bool; fn is_uppercase(self) -> bool; fn is_whitespace(self) -> bool; fn is_ascii(self) -> bool; // Provided method fn is_character(self) -> bool where Self: Sized { ... }
}
Expand description

Common trait for unicode scalar types.

It’s implemented for: char7, char8, char16, and char.

Required Associated Constants§

Source

const MIN: Self

The lowest unicode scalar that can be represented.

Source

const MAX: Self

The highest unicode scalar that can be represented.

Required Methods§

Source

fn byte_len(self) -> usize

Returns the number of bytes needed to represent the scalar value.

Source

fn len_utf8(self) -> usize

Returns the number of bytes needed to encode in UTF-8.

Source

fn len_utf16(self) -> usize

Returns the number of bytes needed to encode in UTF-16.

Source

fn encode_utf8(self, dst: &mut [u8]) -> &mut str

Encodes this scalar as UTF-8 into the provided byte buffer, and then returns the subslice of the buffer that contains the encoded scalar.

§Panics

Panics if the buffer is not large enough. A buffer of length four is large enough to encode any char.

Source

fn to_utf8_bytes(self) -> [u8; 4]

Converts this scalar to an UTF-8 encoded sequence of bytes.

Note that this function always returns a 4-byte array, but the actual UTF-8 sequence may be shorter. The unused bytes are set to 0.

Source

fn encode_utf16(self, dst: &mut [u16]) -> &mut [u16]

Encodes this scalar as UTF-16 into the provided byte buffer, and then returns the subslice of the buffer that contains the encoded scalar.

§Panics

Panics if the buffer is not large enough. A buffer of length 2 is large enough to encode any char.

Source

fn to_digit(self, radix: u32) -> Option<u32>

Converts the scalar to a digit in the given radix.

‘Digit’ is defined to be only the following characters: 0-9, a-z, A-Z.

§Errors

Returns None if the char does not refer to a digit in the given radix.

§Panics

Panics if given a radix larger than 36.

Source

fn to_ascii_uppercase(self) -> Self
where Self: Sized,

Makes a copy of the value in its ASCII upper case equivalent.

ASCII letters ‘a’ to ‘z’ are mapped to ‘A’ to ‘Z’, but non-ASCII letters are unchanged.

Source

fn to_ascii_lowercase(self) -> Self
where Self: Sized,

Makes a copy of the value in its ASCII lower case equivalent.

ASCII letters ‘A’ to ‘Z’ are mapped to ‘a’ to ‘z’, but non-ASCII letters are unchanged.

Source

fn is_noncharacter(self) -> bool

Returns true if this unicode scalar is a noncharacter.

Source

fn is_digit(self, radix: u32) -> bool

Checks if the unicode scalar is a digit in the given radix.

See also to_digit.

Source

fn is_control(self) -> bool

Returns true if this unicode scalar has the general category for control codes.

Source

fn is_nul(self) -> bool

Returns true if this unicode scalar is the nul character (0x00).

Source

fn is_alphabetic(self) -> bool

Returns true if this unicode scalar has the Alphabetic property.

Source

fn is_numeric(self) -> bool

Returns true if this unicode scalar has one of the general categories for numbers.

If you want to parse ASCII decimal digits (0-9) or ASCII base-N, use is_ascii_digit or is_digit instead.

Source

fn is_alphanumeric(self) -> bool

Returns true if this unicode scalar satisfies either is_alphabetic() or is_numeric().

Source

fn is_lowercase(self) -> bool

Returns true if this unicode scalar has the Lowercase property.

Source

fn is_uppercase(self) -> bool

Returns true if this unicode scalar has the Lowercase property.

Source

fn is_whitespace(self) -> bool

Returns true if this unicode scalar has the White_Space property.

Source

fn is_ascii(self) -> bool

Checks if the value is within the ASCII range.

Provided Methods§

Source

fn is_character(self) -> bool
where Self: Sized,

Returns true if this unicode scalar is an abstract character.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl UnicodeScalar for char

Source§

const MIN: Self = '\0'

Source§

const MAX: Self = '\u{10ffff}'

Source§

fn byte_len(self) -> usize

Source§

fn len_utf8(self) -> usize

Source§

fn len_utf16(self) -> usize

Source§

fn encode_utf8(self, dst: &mut [u8]) -> &mut str

Source§

fn to_utf8_bytes(self) -> [u8; 4]

Source§

fn encode_utf16(self, dst: &mut [u16]) -> &mut [u16]

Source§

fn to_digit(self, radix: u32) -> Option<u32>

Source§

fn to_ascii_uppercase(self) -> char

Source§

fn to_ascii_lowercase(self) -> char

Source§

fn is_noncharacter(self) -> bool

Source§

fn is_digit(self, radix: u32) -> bool

Source§

fn is_control(self) -> bool

Source§

fn is_nul(self) -> bool

Source§

fn is_alphabetic(self) -> bool

Source§

fn is_numeric(self) -> bool

Source§

fn is_alphanumeric(self) -> bool

Source§

fn is_lowercase(self) -> bool

Source§

fn is_uppercase(self) -> bool

Source§

fn is_whitespace(self) -> bool

Source§

fn is_ascii(self) -> bool

Implementors§

Source§

impl UnicodeScalar for char7

Source§

const MIN: Self = Self::MIN

Source§

const MAX: Self = Self::MAX

Source§

impl UnicodeScalar for char8

Source§

const MIN: Self = Self::MIN

Source§

const MAX: Self = Self::MAX

Source§

impl UnicodeScalar for char16

Source§

const MIN: Self = Self::MIN

Source§

const MAX: Self = Self::MAX