pub struct Char;
Implementations§
Source§impl Char
impl Char
Sourcepub const fn byte_len(code: u32) -> usize
pub const fn byte_len(code: u32) -> usize
Returns the number of bytes necessary to store the given unicode scalar code
.
Sourcepub const fn is_7bit(code: u32) -> bool
pub const fn is_7bit(code: u32) -> bool
Returns true
if the given unicode scalar code
is a 7bit ASCII code.
Sourcepub const fn is_noncharacter(code: u32) -> bool
pub const fn is_noncharacter(code: u32) -> bool
Returns true
if the given unicode scalar code
is a noncharacter.
Sourcepub const fn utf8_len(first_byte: u8) -> u8
pub const fn utf8_len(first_byte: u8) -> u8
Returns the expected UTF-8 byte length based on the first byte.
This function does not validate UTF-8 but determines how many bytes a valid sequence should occupy based on the leading byte.
- ASCII (0xxxxxxx) → 1 byte
- 2-byte (110xxxxx) → 2 bytes
- 3-byte (1110xxxx) → 3 bytes
- 4-byte (11110xxx) → 4 bytes
§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.
For a stricter check, see utf8_len_checked
.
Sourcepub const fn utf8_len_checked(first_byte: u8) -> Option<u8> ⓘ
pub const fn utf8_len_checked(first_byte: u8) -> Option<u8> ⓘ
Returns the UTF-8 byte length or None
if the first byte is invalid.
This function detects invalid UTF-8 leading bytes and ensures they fall within valid Unicode scalar boundaries.
- Returns
Some(len)
for valid leading bytes. - Returns
None
for invalid first bytes that cannot start a UTF-8 sequence.
§Stricter Handling
- Rejects overlong sequences (C0, C1).
- Enforces the valid UTF-8 upper bound (max
F4
). - Safer for processing untrusted input where malformed UTF-8 must be detected.
For a simpler length-only function, see utf8_len
.
Sourcepub const fn utf8_2bytes_len(code: [u8; 2]) -> u8
👎Deprecated since 0.23.0: Use utf8_len
instead
pub const fn utf8_2bytes_len(code: [u8; 2]) -> u8
utf8_len
insteadReturns the number of bytes needed to store the given unicode scalar code
,
already UTF-8 encoded in 2 bytes.
Sourcepub const fn utf8_3bytes_len(code: [u8; 3]) -> u8
👎Deprecated since 0.23.0: Use utf8_len
instead
pub const fn utf8_3bytes_len(code: [u8; 3]) -> u8
utf8_len
insteadReturns the number of bytes needed to store the given unicode scalar code
,
already UTF-8 encoded in 3 bytes.
Sourcepub const fn utf8_4bytes_len(code: [u8; 4]) -> u8
👎Deprecated since 0.23.0: Use utf8_len
instead
pub const fn utf8_4bytes_len(code: [u8; 4]) -> u8
utf8_len
insteadReturns the number of bytes needed to store the given unicode scalar code
,
already UTF-8 encoded in 4 bytes.
Sourcepub const fn len_utf8(code: char) -> usize
pub const fn len_utf8(code: char) -> usize
Returns the number of bytes needed to encode the given unicode scalar code
as UTF-8.
Sourcepub const fn len_to_utf8(code: char) -> usize
👎Deprecated since 0.23.0: Use len_utf8
instead
pub const fn len_to_utf8(code: char) -> usize
len_utf8
insteadReturns the number of bytes needed to encode the given unicode scalar code
as UTF-8.
Sourcepub const fn to_utf8_bytes(c: char) -> [u8; 4]
pub const fn to_utf8_bytes(c: char) -> [u8; 4]
Converts this char
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.
See also char::encode_utf8
.
Auto Trait Implementations§
impl Freeze for Char
impl RefUnwindSafe for Char
impl Send for Char
impl Sync for Char
impl Unpin for Char
impl UnwindSafe for Char
Blanket Implementations§
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, R> Chain<R> for Twhere
T: ?Sized,
impl<T, R> Chain<R> for Twhere
T: ?Sized,
Source§impl<T> ExtAny for T
impl<T> ExtAny 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§impl<T> ExtMem for Twhere
T: ?Sized,
impl<T> ExtMem 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.§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Hook for T
impl<T> Hook for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more