master v0.1.3
Ondřej Hruška 3 years ago
parent fc116db7b2
commit 3645476e06
  1. 9
      CHANGELOG.md
  2. 8
      Cargo.toml
  3. 19
      src/errors.rs
  4. 17
      src/tests.rs

@ -0,0 +1,9 @@
# 0.1.3
- Update dependency versions
- Correct definition of the error struct (add `impl Error`)
- Add unit tests for the error struct
# 0.1.2
Initial release

@ -1,6 +1,6 @@
[package]
name = "latlon"
version = "0.1.2"
version = "0.1.3"
authors = ["Ondřej Hruška <ondra@ondrovo.com>"]
description = "Parse latitude/longitude from many common formats"
edition = "2018"
@ -11,6 +11,6 @@ categories = ["parser-implementations", "science"]
license = "MIT"
[dependencies]
geo-types = "0.5.0"
regex = "1.3.7"
lazy_static = "1.4.0"
geo-types = "0.7"
regex = "1"
lazy_static = "1.4"

@ -1,5 +1,5 @@
use std::fmt;
use std::fmt::{Display, Formatter};
use std::fmt::{Display, Formatter, Debug};
use std::num::ParseFloatError;
#[derive(Debug)]
@ -17,11 +17,20 @@ impl Display for ParseErrorInternal {
}
}
#[derive(Debug)]
pub struct GeoParseError<T: AsRef<str> + Display>(pub T);
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> + Display> Display for GeoParseError<T> {
impl<T : AsRef<str>> Debug for GeoParseError<T> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "Error parsing coordinates from {}", self.0)
f.debug_tuple("GeoParseError")
.field(&self.0.as_ref())
.finish()
}
}
impl<T : AsRef<str>> std::error::Error for GeoParseError<T> {}

@ -1,4 +1,4 @@
use crate::{parse, parse_lat, parse_lng};
use crate::{parse, parse_lat, parse_lng, GeoParseError};
use geo_types::Point;
#[test]
@ -472,3 +472,18 @@ fn d() {
parse_lng(r#"-180°"#).unwrap();
parse_lng(r#"1°"#).unwrap();
}
#[test]
fn error() {
let e = GeoParseError("Hello");
assert_eq!("GeoParseError(\"Hello\")", format!("{:?}", e));
assert_eq!("GeoParseError(\n \"Hello\",\n)", format!("{:#?}", e));
let e = GeoParseError("Hello2".to_string());
assert_eq!("GeoParseError(\"Hello2\")", format!("{:?}", e));
assert_eq!("GeoParseError(\n \"Hello2\",\n)", format!("{:#?}", e));
let e = GeoParseError(std::borrow::Cow::Owned("Foo".to_string()));
assert_eq!("GeoParseError(\"Foo\")", format!("{:?}", e));
assert_eq!("GeoParseError(\n \"Foo\",\n)", format!("{:#?}", e));
}

Loading…
Cancel
Save