0.1.3
This commit is contained in:
@@ -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
|
||||||
+4
-4
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "latlon"
|
name = "latlon"
|
||||||
version = "0.1.2"
|
version = "0.1.3"
|
||||||
authors = ["Ondřej Hruška <ondra@ondrovo.com>"]
|
authors = ["Ondřej Hruška <ondra@ondrovo.com>"]
|
||||||
description = "Parse latitude/longitude from many common formats"
|
description = "Parse latitude/longitude from many common formats"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
@@ -11,6 +11,6 @@ categories = ["parser-implementations", "science"]
|
|||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
geo-types = "0.5.0"
|
geo-types = "0.7"
|
||||||
regex = "1.3.7"
|
regex = "1"
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4"
|
||||||
|
|||||||
+14
-5
@@ -1,5 +1,5 @@
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::fmt::{Display, Formatter};
|
use std::fmt::{Display, Formatter, Debug};
|
||||||
use std::num::ParseFloatError;
|
use std::num::ParseFloatError;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@@ -17,11 +17,20 @@ impl Display for ParseErrorInternal {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
pub struct GeoParseError<T: AsRef<str>>(pub T);
|
||||||
pub struct GeoParseError<T: AsRef<str> + Display>(pub T);
|
|
||||||
|
|
||||||
impl<T: AsRef<str> + Display> Display for GeoParseError<T> {
|
impl<T: AsRef<str>> Display for GeoParseError<T> {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
||||||
write!(f, "Error parsing coordinates from {}", self.0)
|
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> {}
|
||||||
|
|||||||
+16
-1
@@ -1,4 +1,4 @@
|
|||||||
use crate::{parse, parse_lat, parse_lng};
|
use crate::{parse, parse_lat, parse_lng, GeoParseError};
|
||||||
use geo_types::Point;
|
use geo_types::Point;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -472,3 +472,18 @@ fn d() {
|
|||||||
parse_lng(r#"-180°"#).unwrap();
|
parse_lng(r#"-180°"#).unwrap();
|
||||||
parse_lng(r#"1°"#).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));
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user