1use std::fmt;
2
3#[derive(Debug)]
4pub enum Error {
5 HashTooShort,
6 LengthMismatch { expected: usize, actual: usize },
7 InvalidBase83(u8),
8 ComponentsOutOfRange,
9}
10
11impl fmt::Display for Error {
12 #[inline(always)]
13 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
14 let message = match self {
15 Error::HashTooShort => "blurhash must be at least 6 characters long".to_string(),
16 Error::LengthMismatch { expected, actual } => format!(
17 "blurhash length mismatch: length is {} but it should be {}",
18 actual, expected
19 ),
20 Error::InvalidBase83(byte) => format!("Invalid base83 character: {:?}", *byte as char),
21 Error::ComponentsOutOfRange => "blurhash must have between 1 and 9 components".into(),
22 };
23 write!(f, "{}", message)
24 }
25}
26
27impl std::error::Error for Error {}