I wonder if the validation of the char is non-trivial and unwanted at compile time?
#[inline]
const fn is_valid_scalar(c: u32) -> bool {
match c {
0..=0xD7FF => true,
0xD800..=0xDFFF => false, // surrogate pairs
0xE000..=0x10FFFF => true,
0x110000..=u32::MAX => false, // outside of Unicode range
}
}
But this could be reduced down to a simple if statement that tests for the invalid ranges. #[inline]
const fn is_valid_scalar(c: u32) -> bool {
matches!(c, 0..=0xD7FF) || matches!(c, 0xDE00..=0x10FFFF)
}
But I prefer your version for its clarity. It should compile into the same thing regardless.