-
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
- Loading branch information
Showing
3 changed files
with
96 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,33 @@ | ||
use std::fmt::Write; | ||
|
||
#[derive(Debug, PartialEq)] | ||
#[non_exhaustive] | ||
pub enum PolylineError { | ||
LongitudeCoordError { coord: f64, idx: usize }, | ||
LatitudeCoordError { coord: f64, idx: usize }, | ||
NoLongError { idx: usize }, | ||
DecodeError { 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 { | ||
let mut s = String::new(); | ||
match self { | ||
PolylineError::LongitudeCoordError { coord, idx } => { | ||
write!(&mut s, "Invalid longitude: {} at position {}", coord, idx) | ||
} | ||
PolylineError::LatitudeCoordError { coord, idx } => { | ||
write!(&mut s, "Invalid latitude: {} at position {}", coord, idx) | ||
} | ||
PolylineError::DecodeError { idx } => { | ||
write!(&mut s, "Cannot decode character at index {}", idx) | ||
} | ||
PolylineError::NoLongError { idx } => { | ||
write!(&mut s, "No longitude to go with latitude at index: {}", idx) | ||
} | ||
PolylineError::DecodeCharError => write!(&mut s, "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