utf_64/error.rs
1use std::fmt;
2
3/// Errors that can occur during UTF64 encoding and decoding operations.
4#[derive(Debug, Clone, PartialEq, Eq)]
5pub enum Utf64Error {
6 /// The input contains invalid UTF-8 data that cannot be encoded to UTF64.
7 InvalidUtf8,
8
9 /// The UTF64 data is malformed or contains invalid sequences.
10 InvalidUtf64,
11
12 /// Reserved bits are not zero (violates UTF64 v1.0 specification).
13 ///
14 /// The UTF64 v1.0 specification requires the lower 32 bits of each character to be zero.
15 /// This error indicates data that may be from a future UTF64 specification version,
16 /// or corrupted data.
17 NonZeroReservedBits,
18}
19
20impl fmt::Display for Utf64Error {
21 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22 match self {
23 Utf64Error::InvalidUtf8 => write!(f, "invalid UTF-8 data"),
24 Utf64Error::InvalidUtf64 => write!(f, "invalid UTF64 encoding"),
25 Utf64Error::NonZeroReservedBits => {
26 write!(f, "reserved bits must be zero in UTF64 v1.0")
27 }
28 }
29 }
30}
31
32impl std::error::Error for Utf64Error {}
33
34/// A specialized Result type for UTF64 operations.
35pub type Result<T> = std::result::Result<T, Utf64Error>;