-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to structured errors, inline encoding (#48)
* Switch to structured errors, inline encoding * Simplify Display impl for error * Document error fields * Fix error message case according to convention
- Loading branch information
Showing
3 changed files
with
111 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
//! Errors that can occur during encoding / decoding of Polylines | ||
|
||
#[derive(Debug, PartialEq)] | ||
#[non_exhaustive] | ||
pub enum PolylineError { | ||
LongitudeCoordError { | ||
/// The coordinate value that caused the error due to being outside the range `-180.0..180.0` | ||
coord: f64, | ||
/// The string index of the coordinate error | ||
idx: usize, | ||
}, | ||
LatitudeCoordError { | ||
/// The coordinate value that caused the error due to being outside the range `-90.0..90.0` | ||
coord: f64, | ||
/// The string index of the coordinate error | ||
idx: usize, | ||
}, | ||
NoLongError { | ||
/// The string index of the missing longitude | ||
idx: usize, | ||
}, | ||
DecodeError { | ||
/// The string index of the character that caused the decoding error | ||
idx: usize, | ||
}, | ||
DecodeCharError, | ||
} | ||
|
||
impl std::error::Error for PolylineError {} | ||
impl std::fmt::Display for PolylineError { | ||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { | ||
match self { | ||
PolylineError::LongitudeCoordError { coord, idx } => { | ||
write!(f, "invalid longitude: {} at position {}", coord, idx) | ||
} | ||
PolylineError::LatitudeCoordError { coord, idx } => { | ||
write!(f, "invalid latitude: {} at position {}", coord, idx) | ||
} | ||
PolylineError::DecodeError { idx } => { | ||
write!(f, "cannot decode character at index {}", idx) | ||
} | ||
PolylineError::NoLongError { idx } => { | ||
write!(f, "no longitude to go with latitude at index: {}", idx) | ||
} | ||
PolylineError::DecodeCharError => write!(f, "couldn't decode character"), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters