diff --git a/spatial-coordinate-systems/src/lib.rs b/spatial-coordinate-systems/src/lib.rs index e079c94..9bd46e1 100644 --- a/spatial-coordinate-systems/src/lib.rs +++ b/spatial-coordinate-systems/src/lib.rs @@ -8,8 +8,6 @@ pub mod dms; pub mod plus; pub mod utm; -// use dmm::DMM; -use dms::DMS; use nom::{ branch::alt, character::complete::space0, @@ -42,7 +40,7 @@ impl Direction { pub enum Coordinate { DD(dd::Coordinate), DMS(dms::Coordinate), - // DM(dmm::Coordinate), + // DMM(dmm::Coordinate), UTM(utm::Coordinate), Plus(plus::Coordinate), } @@ -55,7 +53,7 @@ impl Coordinate { alt(( map(dd::Coordinate::parse, Coordinate::DD), map(dms::Coordinate::parse, Coordinate::DMS), - // map(dmm::Coordinate::parse, Coordinate::DM), + // map(dmm::Coordinate::parse, Coordinate::DMM), map(utm::Coordinate::parse, Coordinate::UTM), map(plus::Coordinate::parse, Coordinate::Plus), )), @@ -67,6 +65,46 @@ impl Coordinate { } } +impl TryInto for Coordinate { + type Error = (); + + fn try_into(self) -> Result { + match self { + Coordinate::DD(dd) => dd.try_into().or(Err(())), + // Coordinate::DMM(dm) => dm.try_into(), + Coordinate::DMS(dms) => dms.try_into(), + Coordinate::UTM(utm) => utm.try_into(), + Coordinate::Plus(plus) => plus.try_into(), + } + } +} + +impl From for Coordinate { + fn from(c: dd::Coordinate) -> Self { + Self::DD(c) + } +} +impl From for Coordinate { + fn from(c: dms::Coordinate) -> Self { + Self::DMS(c) + } +} +// impl From for Coordinate { +// fn from(c: dmm::Coordinate) -> Self { +// Self::DMM(c) +// } +// } +impl From for Coordinate { + fn from(c: utm::Coordinate) -> Self { + Self::UTM(c) + } +} +impl From for Coordinate { + fn from(c: plus::Coordinate) -> Self { + Self::Plus(c) + } +} + impl FromStr for Coordinate { type Err = ();