1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use std::error::Error;
use std::fmt;
use crate::Coord;
#[derive(Debug)]
pub enum GeohashError {
InvalidHashCharacter(char),
InvalidCoordinateRange(Coord<f64>),
InvalidLength(usize),
InvalidHash(String),
}
impl fmt::Display for GeohashError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
GeohashError::InvalidHashCharacter(c) => write!(f, "invalid hash character: {}", c),
GeohashError::InvalidCoordinateRange(c) => {
write!(f, "invalid coordinate range: {:?}", c)
}
GeohashError::InvalidLength(len) => write!(
f,
"Invalid length specified: {}. Accepted values are between 1 and 12, inclusive",
len
),
GeohashError::InvalidHash(msg) => write!(f, "Invalid input hash: {}", msg),
}
}
}
impl Error for GeohashError {}