pub struct Char<T>(pub T);Expand description
๐ ๐ ๏ธ Unicode scalars-related low-level const operations.
๐ text/unicode/scalar
ยงTerminology
- A code point is an integer in
U+0000..=U+10FFFF. - A surrogate is a code point in
U+D800..=U+DFFF. - A Unicode scalar value is a code point that is not a surrogate.
Rustโs
charrepresents exactly this set. - A scalar rank is the zero-based position of a scalar value in the ordered set of all Unicode scalar values, with the surrogate range omitted.
ยงMethods
-
- scalar_from_rank.
- scalar_rank.
- is_valid_code.
- is_valid_scalar.
- is_surrogate (high, low).
- len_bytes.
- len_utf8 (unchecked).
- width (common).
- is_ascii (unchecked).
- is_noncharacter.
- is_combining (common).
- is_control (common).
- is_fullwidth (common).
- as_ascii (unchecked).
- to_utf8_bytes (unchecked).
- write_utf8_to_unchecked.
- random_next.
- random_from_seed.
See also Str.
Tuple Fieldsยง
ยง0: TImplementationsยง
Sourceยงimpl Char<char>
ยงMethods over char
impl Char<char>
ยงMethods over char
Sourcepub const fn len_utf8(self) -> usize
pub const fn len_utf8(self) -> usize
Returns the number of bytes needed to encode the given Unicode scalar as UTF-8.
See also Char::<u32>len_utf8.
Sourcepub const fn width(self) -> usize
pub const fn width(self) -> usize
Returns the monospace display width.
- 0: Non-printing characters (controls, combining marks)
- 1: Regular characters (Latin, Greek, Cyrillic, etc.)
- 2: Wide characters (CJK, emoji, fullwidth forms)
Sourcepub const fn width_common(self) -> usize
pub const fn width_common(self) -> usize
Returns the monospace display width using faster calculation.
Uses optimized checks that cover common cases but may incorrectly report some obscure Unicode characters as 1 width instead of 2.
Sourcepub const fn is_combining(self) -> bool
pub const fn is_combining(self) -> bool
Returns true for all Unicode combining characters.
Includes musical notation, historic scripts, and obscure diacritics.
Comprehensive but slightly slower than is_combining_common.
Sourcepub const fn is_combining_common(self) -> bool
pub const fn is_combining_common(self) -> bool
Returns true for common combining marks used in modern text.
Covers Latin, Greek, and most European language diacritics. Fast and suitable for 95% of use cases.
Sourcepub const fn is_control(self) -> bool
pub const fn is_control(self) -> bool
Returns true for all Unicode control characters.
Sourcepub const fn is_control_common(self) -> bool
pub const fn is_control_common(self) -> bool
Returns true for common Unicode control characters.
Just ASCII, zero-width spaces, bidi formatting, word joiners and invisible operators.
Sourcepub const fn is_fullwidth(self) -> bool
pub const fn is_fullwidth(self) -> bool
Returns true for all Unicode fullwidth characters.
Sourcepub const fn is_fullwidth_common(self) -> bool
pub const fn is_fullwidth_common(self) -> bool
Returns true for common fullwidth characters (ASCII variants, basic CJK)
Sourcepub const fn to_utf8_bytes(self) -> [u8; 4]
pub const fn to_utf8_bytes(self) -> [u8; 4]
Converts this Unicode scalar to a UTF-8 encoded byte sequence.
Always returns a [u8; 4] array, with unused bytes set to 0.
See also char::encode_utf8.
Sourcepub const fn write_utf8_to(self, buf: &mut [u8]) -> usize
pub const fn write_utf8_to(self, buf: &mut [u8]) -> usize
Writes this Unicode scalar as UTF-8 into buf.
Returns the number of bytes written.
A buffer of 4 bytes is always large enough for any Unicode scalar.
ยงPanics
Panics if buf.len() < self.0.len_utf8().
Sourcepub const fn as_ascii(self) -> &'static str โ
pub const fn as_ascii(self) -> &'static str โ
Returns the ASCII representation as a &'static str, or "" if non-ASCII.
Sourcepub const fn as_ascii_unchecked(self) -> &'static str โ
pub const fn as_ascii_unchecked(self) -> &'static str โ
Sourcepub const fn to_ascii_fold(self) -> Option<char> โ
pub const fn to_ascii_fold(self) -> Option<char> โ
Converts a character to its closest ASCII equivalent, if possible.
This function attempts to replace accented or special characters with
their ASCII counterparts. If a mapping exists, it returns Some(char),
otherwise, it returns None.
Sourcepub const fn to_ascii_fold_unchecked(self) -> char
pub const fn to_ascii_fold_unchecked(self) -> char
Converts a character to its closest ASCII equivalent, or returns the input character if no mapping exists.
This function is similar to
to_ascii_fold, but never returns None.
If no ASCII equivalent exists, the input character is returned unchanged.
Sourcepub const fn random_next(rng: &mut Pcg32) -> char
pub const fn random_next(rng: &mut Pcg32) -> char
Returns a Unicode scalar selected from the next output of rng.
Sourcepub const fn random_from_seed(seed: u64) -> char
pub const fn random_from_seed(seed: u64) -> char
Returns a Unicode scalar deterministically selected from seed.
Sourceยงimpl Char<u16>
ยงMethods over u16.
impl Char<u16>
ยงMethods over u16.
Sourcepub const fn is_surrogate(self) -> bool
pub const fn is_surrogate(self) -> bool
Returns true if the given Unicode scalar code is a surrogate code point.
Sourcepub const fn is_surrogate_high(self) -> bool
pub const fn is_surrogate_high(self) -> bool
Returns true if the given Unicode scalar code is a leading surrogate.
Sourcepub const fn is_surrogate_low(self) -> bool
pub const fn is_surrogate_low(self) -> bool
Returns true if the given Unicode scalar code is a trailing surrogate.
Sourceยงimpl Char<u32>
ยงMethods over u32.
impl Char<u32>
ยงMethods over u32.
Sourcepub const MAX_CODE_POINT: u32 = 0x10_FFFF
pub const MAX_CODE_POINT: u32 = 0x10_FFFF
Maximum Unicode code point.
Sourcepub const SCALAR_COUNT: u32
pub const SCALAR_COUNT: u32
Number of Unicode scalar values.
Sourcepub const SURROGATE_COUNT: u32
pub const SURROGATE_COUNT: u32
Number of Unicode surrogate code points.
Sourcepub const SURROGATE_START: u32 = 0xD800
pub const SURROGATE_START: u32 = 0xD800
First Unicode surrogate code point.
Sourcepub const SURROGATE_END: u32 = 0xDFFF
pub const SURROGATE_END: u32 = 0xDFFF
Last Unicode surrogate code point.
Sourcepub const SURROGATE_HIGH_END: u32 = 0xDBFF
pub const SURROGATE_HIGH_END: u32 = 0xDBFF
Last high-surrogate code point, also called a leading surrogate.
Sourcepub const SURROGATE_LOW_START: u32 = 0xDC00
pub const SURROGATE_LOW_START: u32 = 0xDC00
First low-surrogate code point, also called a trailing surrogate.
Sourcepub const fn scalar_from_rank(rank: u32) -> u32
pub const fn scalar_from_rank(rank: u32) -> u32
Maps a dense Unicode scalar rank to its scalar value.
Scalar indices are contiguous in 0..SCALAR_COUNT, with the surrogate
range omitted from the resulting values.
ยงPanics
Panics if rank >= SCALAR_COUNT.
Sourcepub const fn scalar_rank(self) -> Option<u32> โ
pub const fn scalar_rank(self) -> Option<u32> โ
Returns the dense scalar rank of this value,
or None if it is not a Unicode scalar value.
Sourcepub const fn is_valid_code(self) -> bool
pub const fn is_valid_code(self) -> bool
Checks whether the value is a Unicode code point.
A valid Unicode code point is any integer in the range: 0..=MAX_CODE_POINT.
This includes surrogate code points which are valid code points but cannot be represented as Unicode scalars.
ยงExamples
assert!(Char('A' as u32).is_valid_code()); // regular character
assert!(Char(0x00).is_valid_code()); // NULL is valid
assert!(Char(0x10FFFF).is_valid_code()); // maximum Unicode code point
// surrogates are valid code points:
assert!(Char(0xD800).is_valid_code()); // high surrogate
assert!(Char(0xDFFF).is_valid_code()); // low surrogate
// invalid:
assert!(!Char(0x110000).is_valid_code()); // above max UnicodeSourcepub const fn is_valid_scalar(self) -> bool
pub const fn is_valid_scalar(self) -> bool
Checks whether the value is a Unicode scalar value representable as char.
This excludes surrogate code points, which are invalid in UTF-8 and cannot be represented as Unicode scalars.
ยงExamples
assert!(Char('A' as u32).is_valid_scalar()); // regular character
assert!(Char(0x00).is_valid_scalar()); // NULL is valid
assert!(Char(0x10FFFF).is_valid_scalar()); // maximum Unicode scalar
// invalid:
assert!(!Char(0xD800).is_valid_scalar()); // high surrogate
assert!(!Char(0xDFFF).is_valid_scalar()); // low surrogate
assert!(!Char(0x110000).is_valid_scalar()); // above max UnicodeSourcepub const fn is_surrogate(self) -> bool
pub const fn is_surrogate(self) -> bool
Returns true if the value is a Unicode surrogate code point.
Sourcepub const fn is_surrogate_high(self) -> bool
pub const fn is_surrogate_high(self) -> bool
Returns true if the value is a Unicode high surrogate code point.
Sourcepub const fn is_surrogate_low(self) -> bool
pub const fn is_surrogate_low(self) -> bool
Returns true if the value is a Unicode low surrogate code point.
Sourcepub const fn len_bytes(self) -> usize
pub const fn len_bytes(self) -> usize
Returns the bytes required to store the given Unicode code point in a non-UTF encoding.
This function does not determine the UTF-8 byte length.
It assumes a simple encoding where values up to 0xFF use 1 byte,
0x100..=0xFFFF use 2 bytes, and anything larger uses 3 bytes.
Sourcepub const fn len_utf8(self) -> Option<usize> โ
pub const fn len_utf8(self) -> Option<usize> โ
Returns the number of bytes required to encode the given Unicode scalar as UTF-8.
Returns None if itโs not a valid Unicode scalar.
Sourcepub const fn len_utf8_unchecked(self) -> usize
pub const fn len_utf8_unchecked(self) -> usize
Returns the UTF-8 byte length of the current Unicode scalar without validation.
Assumes the code is a valid Unicode scalar.
Use len_utf8 for a checked version.
Sourcepub const fn width(self) -> usize
pub const fn width(self) -> usize
Returns the monospace display width.
- 0: Non-printing characters (controls, combining marks)
- 1: Regular characters (Latin, Greek, Cyrillic, etc.)
- 2: Wide characters (CJK, emoji, fullwidth forms)
Sourcepub const fn width_common(self) -> usize
pub const fn width_common(self) -> usize
Returns the monospace display width using faster calculation.
Uses optimized checks that cover common cases but may incorrectly report some obscure Unicode characters as 1 width instead of 2.
Sourcepub const fn is_ascii(self) -> bool
pub const fn is_ascii(self) -> bool
Checks if the given value is a 7-bit ASCII character (U+0000..=U+007F).
Sourcepub const fn is_noncharacter(self) -> bool
pub const fn is_noncharacter(self) -> bool
Returns true if the given Unicode scalar code is a noncharacter.
Note that this also checks against reserved, potential non-characters.
Sourcepub const fn is_combining(self) -> bool
pub const fn is_combining(self) -> bool
Returns true for all Unicode combining characters.
Includes musical notation, historic scripts, and obscure diacritics.
Comprehensive but slightly slower than is_combining_common.
Sourcepub const fn is_combining_common(self) -> bool
pub const fn is_combining_common(self) -> bool
Returns true for common combining marks used in modern text.
Covers Latin, Greek, and most European language diacritics. Fast and suitable for 95% of use cases.
Sourcepub const fn is_control(self) -> bool
pub const fn is_control(self) -> bool
Returns true for all Unicode control characters.
Sourcepub const fn is_control_common(self) -> bool
pub const fn is_control_common(self) -> bool
Returns true for common Unicode control characters.
Just ASCII, zero-width spaces, bidi formatting, word joiners and invisible operators.
Sourcepub const fn is_fullwidth(self) -> bool
pub const fn is_fullwidth(self) -> bool
Returns true for all Unicode fullwidth characters.
Sourcepub const fn is_fullwidth_common(self) -> bool
pub const fn is_fullwidth_common(self) -> bool
Returns true for common fullwidth characters (ASCII variants, basic CJK)
Sourcepub const fn as_ascii(self) -> &'static str โ
pub const fn as_ascii(self) -> &'static str โ
Returns the ASCII &'static str representation of the value, or "" if non-ASCII.
Sourcepub const fn as_ascii_unchecked(self) -> &'static str โ
pub const fn as_ascii_unchecked(self) -> &'static str โ
Returns the ASCII &'static str representation of the value, or panics if non-ASCII.
ยงPanics
Panics if the character is not ASCII.
Sourcepub const fn to_utf8_bytes(self) -> Option<[u8; 4]> โ
pub const fn to_utf8_bytes(self) -> Option<[u8; 4]> โ
Converts the Unicode scalar value to a UTF-8 encoded byte sequence array.
Returns None if the value is not a valid Unicode scalar.
The result is always a [u8; 4] array, with unused bytes set to 0.
See also char::encode_utf8.
Sourcepub const fn to_utf8_bytes_unchecked(self) -> [u8; 4]
pub const fn to_utf8_bytes_unchecked(self) -> [u8; 4]
Converts the Unicode scalar value to a UTF-8 encoded byte sequence without validation.
Assumes the value is a valid Unicode scalar.
Always returns a [u8; 4] array, with unused bytes set to 0.
See also Char::to_utf8_bytes for a checked version.
Sourcepub const fn write_utf8_to_unchecked(self, buf: &mut [u8]) -> usize
pub const fn write_utf8_to_unchecked(self, buf: &mut [u8]) -> usize
Writes this Unicode scalar as UTF-8 into buf without validation.
Returns the number of bytes written.
A buffer of 4 bytes is always large enough for any Unicode scalar.
ยงPanics
Panics if buf.len() < self.0.len_utf8().
Sourcepub const fn random_next(rng: &mut Pcg32) -> u32
pub const fn random_next(rng: &mut Pcg32) -> u32
Returns a Unicode scalar selected from the next output of rng.
Sourcepub const fn random_from_seed(seed: u64) -> u32
pub const fn random_from_seed(seed: u64) -> u32
Returns a Unicode scalar deterministically selected from seed.
Sourceยงimpl Char<u8>
ยงMethods over u8.
impl Char<u8>
ยงMethods over u8.
Sourcepub const fn len_utf8(self) -> Option<usize> โ
pub const fn len_utf8(self) -> Option<usize> โ
Returns the expected UTF-8 byte length based on the given first byte, or None if invalid.
LUT based (256-byte array).
Sourcepub const fn len_utf8_unchecked(self) -> usize
pub const fn len_utf8_unchecked(self) -> usize
Returns the expected UTF-8 byte length based on the given first byte, or 0 if invalid.
LUT based (256-byte array).
Sourcepub const fn len_utf8_match(self) -> Option<usize> โ
pub const fn len_utf8_match(self) -> Option<usize> โ
Returns the expected UTF-8 byte length based on the given first byte, or None if invalid.
Match based, for when memory accesses are more expensive than branches.
Sourcepub const fn len_utf8_match_naive(self) -> usize
pub const fn len_utf8_match_naive(self) -> usize
Returns the expected UTF-8 byte length based on the given first byte.
Match based, for when memory accesses are more expensive than branches.
This function does not validate UTF-8 but determines how many bytes a valid sequence should occupy based on the leading byte.
ยงCaveat
- If used on malformed UTF-8, it may suggest a length longer than the actual valid sequence.
- Always use in conjunction with proper UTF-8 validation if handling untrusted input.
Sourcepub const fn is_utf8_boundary(self) -> bool
pub const fn is_utf8_boundary(self) -> bool
Returns true if this byte is a valid starting point for a UTF-8 sequence.
This checks if the byte is not a UTF-8 continuation byte (i.e., itโs either an ASCII character or a valid leading byte of a multi-byte sequence).
Sourcepub const fn is_utf8_continuation(self) -> bool
pub const fn is_utf8_continuation(self) -> bool
Returns true if this byte is a UTF-8 continuation byte.
Continuation bytes have the bit pattern 10xxxxxx.
Sourcepub const fn as_char(self) -> char
pub const fn as_char(self) -> char
Returns the current byte as a char.
See char::from(u8).
Sourceยงimpl Char<&[u8]>
ยงMethods over u8 slice.
impl Char<&[u8]>
ยงMethods over u8 slice.
Sourcepub const fn to_char(self, index: usize) -> Option<(char, usize)> โ
pub const fn to_char(self, index: usize) -> Option<(char, usize)> โ
Decodes a UTF-8 scalar at index.
Returns Some((char, len)) if the input is a valid UTF-8 sequence
and the decoded value is a valid Unicode scalar.
Returns None if:
- The index is out of bounds.
- The bytes do not form a valid UTF-8 sequence.
- The decoded value is not a valid Unicode scalar.
This is implemented via Char::to_scalar().
ยงExamples
// Valid UTF-8 sequence
let result = Char(b"\xE2\x82\xAC").to_char(0); // โฌ
assert_eq!(result, Some(('โฌ', 3)));
// Invalid continuation bytes
let invalid_continuation = Char(b"\xE2\x41\xAC").to_char(0);
assert_eq!(invalid_continuation, None);
// Surrogate code point
let surrogate = Char(b"\xED\xA0\x80").to_char(0); // U+D800
assert_eq!(surrogate, None);
// Out of bounds index
let out_of_bounds = Char(b"hello").to_char(10);
assert_eq!(out_of_bounds, None);
// Incomplete sequence
let incomplete = Char(b"\xE2\x82").to_char(0); // Missing third byte
assert_eq!(incomplete, None);ยงFeatures
Uses the unsafe_str feature to skip duplicated validation checks.
Sourcepub const fn to_char_lenient(self, index: usize) -> (char, usize) โ
pub const fn to_char_lenient(self, index: usize) -> (char, usize) โ
Decodes a UTF-8 scalar leniently at index, validating only the final Unicode scalar.
This method is forgiving of UTF-8 encoding errors but ensures the result is a valid Unicode scalar value.
- Does not validate UTF-8 continuation bytes (may decode malformed sequences).
- If the leading byte is invalid it returns the replacement character (
๏ฟฝ).
This is implemented via Char::to_scalar_unchecked().
ยงPanics
Panics if the decoded value is not a valid Unicode scalar value,
or if the index is out of bounds.
ยงExamples
// Valid UTF-8 sequence
let result = Char(b"\xE2\x82\xAC").to_char_lenient(0); // โฌ
assert_eq!(result, ('โฌ', 3));
// Invalid UTF-8 but decodes to valid scalar - behavior depends on input
// This may return unexpected characters rather than panicking
let result = Char(b"\xE2\x41\xAC").to_char_lenient(0);
assert_eq!(result, ('\u{206c}', 3));
// Surrogate code point - will panic
// let result = Char(b"\xED\xA0\x80").to_char_lenient(0); // PANIC: U+D800 is invalid
// Out of bounds index - will panic
// let result = Char(b"hello").to_char_lenient(10); // PANIC: index out of boundsSourcepub const unsafe fn to_char_unchecked(self, index: usize) -> (char, usize) โ
Available on crate feature unsafe_str and non-crate feature safe_text only.
pub const unsafe fn to_char_unchecked(self, index: usize) -> (char, usize) โ
unsafe_str and non-crate feature safe_text only.Decodes a UTF-8 scalar at index without any validation.
If the leading byte is invalid it returns the replacement character (๏ฟฝ).
This is implemented via Char::to_scalar_unchecked.
ยงSafety
The caller must ensure that:
indexis within bounds ofbytesbytes[index..]contains a valid UTF-8 sequence- The decoded value is a valid Unicode scalar.
Violating these conditions may lead to undefined behavior.
Sourcepub const fn to_scalar(self, index: usize) -> Option<(u32, usize)> โ
pub const fn to_scalar(self, index: usize) -> Option<(u32, usize)> โ
Decodes a UTF-8 scalar from the given byte slice, starting at index.
Returns (scalar, len), where scalar is the decoded Unicode scalar,
and len is the number of bytes consumed.
Returns None if:
- The index is out of bounds.
- The bytes do not form a valid UTF-8 sequence.
- The decoded value is not a valid Unicode scalar.
ยงExamples
assert_eq!(Char("ฤฆ".as_bytes()).to_scalar(0), Some((u32::from('ฤฆ'), 2)));
let invalid = b"\x80"; // Invalid leading byte
assert_eq!(Char(invalid).to_scalar(0), None);Sourcepub const fn to_scalar_unchecked(self, index: usize) -> (u32, usize) โ
pub const fn to_scalar_unchecked(self, index: usize) -> (u32, usize) โ
Decodes a UTF-8 scalar from the given byte slice, starting at index, without validation.
Returns (scalar, len), where scalar is the decoded Unicode scalar,
and len is the number of bytes consumed.
It assumes bytes[index..] contains a valid UTF-8 sequence,
and it doesnโt validate the resulting Unicode scalar.
If the leading byte is invalid it returns the replacement character (๏ฟฝ).
ยงPanics
It will panic if the index is out of bounds.
Sourcepub const fn has_overlong_encoding(self, index: usize, len: usize) -> bool
pub const fn has_overlong_encoding(self, index: usize, len: usize) -> bool
Returns true if the UTF-8 sequence starting at index is overlong encoded.
This method only checks for overlong encodings, but not other UTF-8 validity rules. It does not verify continuation byte patterns nor invalid scalar values.
Overlong encodings use more bytes than necessary to represent a character, which is invalid in well-formed UTF-8.
ยงExamples
assert!(Char(b"\xE0\x80\x80").has_overlong_encoding(0, 3)); // overlong encoding
assert!(!Char(b"\xE0\xA0\x80").has_overlong_encoding(0, 3)); // valid 3-byte sequenceSourcepub const fn has_valid_continuation(self, index: usize, len: usize) -> bool
pub const fn has_valid_continuation(self, index: usize, len: usize) -> bool
Verifies that the continuation bytes following a UTF-8 leading byte are properly formatted.
Each continuation byte must match the pattern 10xxxxxx (i.e., have the high bits 0b10).
This ensures the byte sequence follows proper UTF-8 encoding rules.
This method only verifies correct syntax, but not correct semantics. It does not check for overlong encodings nor invalid scalar values.
ยงExamples
assert!(Char(b"\xE2\x82\xAC").has_valid_continuation(0, 3)); // euro sign โฌ
assert!(!Char(b"\xE2\x41\xAC").has_valid_continuation(0, 3)); // second byte is ASCII 'A'
assert!(!Char(b"\xC2").has_valid_continuation(0, 2)); // incomplete sequenceSourcepub const fn is_utf8_boundary(self, index: usize) -> bool
pub const fn is_utf8_boundary(self, index: usize) -> bool
Returns true if the byte at index is a valid starting point for a UTF-8 sequence.
This checks if the byte is not a UTF-8 continuation byte (i.e., itโs either an ASCII character or a valid leading byte of a multi-byte sequence).
Useful for safely starting UTF-8 decoding from an arbitrary position in a byte slice.
Sourcepub const fn ceil_utf8_boundary(self, index: usize) -> usize
pub const fn ceil_utf8_boundary(self, index: usize) -> usize
Returns the smallest UTF-8 boundary >= index.
Sourcepub const fn floor_utf8_boundary(self, index: usize) -> usize
pub const fn floor_utf8_boundary(self, index: usize) -> usize
Returns the greatest UTF-8 boundary <= index.
If index > self.len(), starts from self.len().
This only checks boundary shape, not full UTF-8 validity. It is intended for already-valid UTF-8 byte slices.
Sourceยงimpl<const N: usize> Char<&[u8; N]>
Method wrappers over a byte array reference.
impl<const N: usize> Char<&[u8; N]>
Method wrappers over a byte array reference.
Sourcepub const fn to_char(self, index: usize) -> Option<(char, usize)> โ
pub const fn to_char(self, index: usize) -> Option<(char, usize)> โ
A wrapper over to_char().
Sourcepub const fn to_char_lenient(self, index: usize) -> (char, usize) โ
pub const fn to_char_lenient(self, index: usize) -> (char, usize) โ
A wrapper over to_char_lenient().
Sourcepub const unsafe fn to_char_unchecked(self, index: usize) -> (char, usize) โ
Available on crate feature unsafe_str and non-crate feature safe_text only.
pub const unsafe fn to_char_unchecked(self, index: usize) -> (char, usize) โ
unsafe_str and non-crate feature safe_text only.Sourcepub const fn to_scalar(self, index: usize) -> Option<(u32, usize)> โ
pub const fn to_scalar(self, index: usize) -> Option<(u32, usize)> โ
A wrapper over to_scalar().
Sourcepub const fn to_scalar_unchecked(self, index: usize) -> (u32, usize) โ
pub const fn to_scalar_unchecked(self, index: usize) -> (u32, usize) โ
A wrapper over to_scalar_unchecked().
Sourcepub const fn has_overlong_encoding(self, index: usize, len: usize) -> bool
pub const fn has_overlong_encoding(self, index: usize, len: usize) -> bool
A wrapper over has_overlong_encoding().
Sourcepub const fn has_valid_continuation(self, index: usize, len: usize) -> bool
pub const fn has_valid_continuation(self, index: usize, len: usize) -> bool
A wrapper over has_valid_continuation().
Sourcepub const fn is_utf8_boundary(self, index: usize) -> bool
pub const fn is_utf8_boundary(self, index: usize) -> bool
A wrapper over is_utf8_boundary().
Sourcepub const fn ceil_utf8_boundary(self, index: usize) -> usize
pub const fn ceil_utf8_boundary(self, index: usize) -> usize
A wrapper over ceil_utf8_boundary().
Sourcepub const fn floor_utf8_boundary(self, index: usize) -> usize
pub const fn floor_utf8_boundary(self, index: usize) -> usize
A wrapper over floor_utf8_boundary().
Trait Implementationsยง
Auto Trait Implementationsยง
impl<T> Freeze for Char<T>where
T: Freeze,
impl<T> RefUnwindSafe for Char<T>where
T: RefUnwindSafe,
impl<T> Send for Char<T>where
T: Send,
impl<T> Sync for Char<T>where
T: Sync,
impl<T> Unpin for Char<T>where
T: Unpin,
impl<T> UnsafeUnpin for Char<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for Char<T>where
T: UnwindSafe,
Blanket Implementationsยง
Sourceยงimpl<T> AnyExt for T
impl<T> AnyExt for T
Sourceยงfn type_hash_with<H: Hasher>(&self, hasher: H) -> u64
fn type_hash_with<H: Hasher>(&self, hasher: H) -> u64
TypeId of Self using a custom hasher.Sourceยงfn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
Sourceยงfn as_any_box(self: Box<Self>) -> Box<dyn Any>where
Self: Sized,
fn as_any_box(self: Box<Self>) -> Box<dyn Any>where
Self: Sized,
alloc only.Sourceยงimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Sourceยงfn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Sourceยงimpl<T> ByteSized for T
impl<T> ByteSized for T
Sourceยงconst BYTE_ALIGN: usize = _
const BYTE_ALIGN: usize = _
Sourceยงfn byte_align(&self) -> usize
fn byte_align(&self) -> usize
Sourceยงfn ptr_size_ratio(&self) -> [usize; 2]
fn ptr_size_ratio(&self) -> [usize; 2]
Sourceยงimpl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Sourceยงimpl<T> MemExt for Twhere
T: ?Sized,
impl<T> MemExt for Twhere
T: ?Sized,
Sourceยงconst NEEDS_DROP: bool = _
const NEEDS_DROP: bool = _
Sourceยงfn mem_align_of<T>() -> usize
fn mem_align_of<T>() -> usize
Sourceยงfn mem_align_of_val(&self) -> usize
fn mem_align_of_val(&self) -> usize
Sourceยงfn mem_size_of<T>() -> usize
fn mem_size_of<T>() -> usize
Sourceยงfn mem_size_of_val(&self) -> usize
fn mem_size_of_val(&self) -> usize
Sourceยงfn mem_needs_drop(&self) -> bool
fn mem_needs_drop(&self) -> bool
true if dropping values of this type matters. Read moreSourceยงfn mem_forget(self)where
Self: Sized,
fn mem_forget(self)where
Self: Sized,
self without running its destructor. Read moreSourceยงfn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
Sourceยงunsafe fn mem_zeroed<T>() -> T
unsafe fn mem_zeroed<T>() -> T
unsafe_layout only.T represented by the all-zero byte-pattern. Read moreSourceยงunsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe_layout only.T represented by the all-zero byte-pattern. Read moreSourceยงfn mem_as_bytes(&self) -> &[u8] โ
fn mem_as_bytes(&self) -> &[u8] โ
unsafe_slice only.