Rust crate for geo coord parsing https://crates.io/crates/latlon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
latlon/src/errors.rs

36 lines
932 B

use std::fmt;
use std::fmt::{Display, Formatter, Debug};
use std::num::ParseFloatError;
#[derive(Debug)]
pub(crate) struct ParseErrorInternal;
impl From<ParseFloatError> for ParseErrorInternal {
fn from(_: ParseFloatError) -> Self {
ParseErrorInternal
}
}
impl Display for ParseErrorInternal {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.write_str("Parse error")
}
}
pub struct GeoParseError<T: AsRef<str>>(pub T);
impl<T: AsRef<str>> Display for GeoParseError<T> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "Error parsing coordinates from {}", self.0.as_ref())
}
}
impl<T : AsRef<str>> Debug for GeoParseError<T> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.debug_tuple("GeoParseError")
.field(&self.0.as_ref())
.finish()
}
}
impl<T : AsRef<str>> std::error::Error for GeoParseError<T> {}