east_asian_width/
error.rs

1/// Error type for East Asian Width operations
2#[derive(Debug, Clone, PartialEq, Eq)]
3pub enum EastAsianWidthError {
4    /// Invalid Unicode code point (exceeds 0x10FFFF)
5    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
20/// Validates that the input is a valid Unicode code point
21pub 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}