Cleanup error reporting

This commit is contained in:
Austen Adler 2023-03-25 00:55:11 -04:00
parent 93523beb37
commit 8c6fff2a3b
5 changed files with 9 additions and 10 deletions

View File

@ -101,10 +101,10 @@ impl TryFrom<LatLon> for Coordinate {
} }
impl FromStr for Coordinate { impl FromStr for Coordinate {
type Err = (); type Err = Error;
fn from_str(i: &str) -> Result<Self, Self::Err> { fn from_str(i: &str) -> Result<Self, Self::Err> {
Self::parse(i).map_err(|_| ()).map(|(_, ret)| ret) Self::parse(i).map_err(Into::into).map(|(_, ret)| ret)
} }
} }

View File

@ -42,10 +42,10 @@ impl Coordinate {
} }
impl FromStr for Coordinate { impl FromStr for Coordinate {
type Err = (); type Err = Error;
fn from_str(i: &str) -> Result<Self, Self::Err> { fn from_str(i: &str) -> Result<Self, Self::Err> {
Self::parse(i).map_err(|_| ()).map(|(_, ret)| ret) Self::parse(i).map_err(Into::into).map(|(_, ret)| ret)
} }
} }

View File

@ -134,10 +134,10 @@ impl DMS {
} }
impl FromStr for Coordinate { impl FromStr for Coordinate {
type Err = (); type Err = Error;
fn from_str(i: &str) -> Result<Self, Self::Err> { fn from_str(i: &str) -> Result<Self, Self::Err> {
Self::parse(i).map_err(|_| ()).map(|(_, ret)| ret) Self::parse(i).map_err(Into::into).map(|(_, ret)| ret)
} }
} }

View File

@ -1,3 +1,4 @@
use crate::Error;
use crate::LatLon; use crate::LatLon;
use nom::{bytes::complete::take_while, combinator::map_opt, IResult}; use nom::{bytes::complete::take_while, combinator::map_opt, IResult};
use std::{fmt, str::FromStr}; use std::{fmt, str::FromStr};
@ -29,10 +30,10 @@ impl Coordinate {
} }
impl FromStr for Coordinate { impl FromStr for Coordinate {
type Err = (); type Err = Error;
fn from_str(i: &str) -> Result<Self, Self::Err> { fn from_str(i: &str) -> Result<Self, Self::Err> {
Self::parse(i).map_err(|_| ()).map(|(_, ret)| ret) Self::parse(i).map_err(Into::into).map(|(_, ret)| ret)
} }
} }

View File

@ -134,8 +134,6 @@ mod tests {
let cvt = Coordinate::from_str($tt); let cvt = Coordinate::from_str($tt);
eprintln!("Testing: {} => {:?}", $tt, cvt); eprintln!("Testing: {} => {:?}", $tt, cvt);
assert!(cvt.is_ok()); assert!(cvt.is_ok());
eprintln!("Now converting to latlon");
// assert!(dbg!(TryInto::<LatLon>::try_into(cvt.unwrap())).is_ok());
}}; }};
} }