east_asian_width/
error.rs1#[derive(Debug, Clone, PartialEq, Eq)]
3pub enum EastAsianWidthError {
4 InvalidCodePoint(u32),
6}
7
8impl std::fmt::Display for EastAsianWidthError {
9 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
10 match self {
11 EastAsianWidthError::InvalidCodePoint(cp) => {
12 write!(f, "Code point 0x{:X} exceeds Unicode range (0x10FFFF)", cp)
13 }
14 }
15 }
16}
17
18impl std::error::Error for EastAsianWidthError {}
19
20pub fn validate_code_point(code_point: u32) -> Result<(), EastAsianWidthError> {
22 if code_point > 0x10FFFF {
23 return Err(EastAsianWidthError::InvalidCodePoint(code_point));
24 }
25 Ok(())
26}