1use core::fmt::Display;
4
5#[derive(Debug, Clone, PartialEq)]
11pub enum Error {
12 InvalidAngle(f64, f64),
14 InvalidLatitudeDegrees(i32),
16 InvalidLongitudeDegrees(i32),
18 InvalidMinutes(u32),
20 InvalidSeconds(f32),
22 InvalidCharacter(char, String),
24 InvalidWhitespace(String),
26 InvalidNumericFormat(String),
28 InvalidCoordinate,
30 #[cfg(feature = "urn")]
32 InvalidUrnScheme,
33}
34
35impl Display for Error {
40 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
41 match self {
42 Error::InvalidAngle(v, limit) => write!(
43 f,
44 "Invalid value `{v}` for angle; expecting `-{limit}..={limit}`."
45 ),
46 Error::InvalidLatitudeDegrees(v) => write!(
47 f,
48 "Invalid value `{v}` for latitude degrees; expecting `-90..=90`."
49 ),
50 Error::InvalidLongitudeDegrees(v) => write!(
51 f,
52 "Invalid value `{v}` for longitude degrees; expecting `-180..=180`."
53 ),
54 Error::InvalidMinutes(v) => {
55 write!(f, "Invalid value `{v}` for minutes; expecting `0..60`.")
56 }
57 Error::InvalidSeconds(v) => {
58 write!(f, "Invalid value `{v}` for seconds; expecting `0.0..60.0`.")
59 }
60 Error::InvalidCharacter(c, s) => {
61 write!(f, "Invalid character `{c}` parsing value `\"{s}\"`.")
62 }
63 Error::InvalidWhitespace(s) => {
64 write!(f, "Invalid whitespace parsing value `\"{s}\"`.")
65 }
66 Error::InvalidNumericFormat(s) => {
67 write!(f, "Invalid numeric format parsing value `\"{s}\"`.")
68 }
69 Error::InvalidCoordinate => {
70 write!(
71 f,
72 "Invalid `Latitude` and `Longitude` pair constructing `Coordinate`."
73 )
74 }
75 #[cfg(feature = "url")]
76 Error::InvalidUrnScheme => write!(f, "URI scheme must be `geo:`."),
77 }
78 }
79}
80
81impl std::error::Error for Error {}