63 lines
1.4 KiB
Rust
63 lines
1.4 KiB
Rust
use std::str::FromStr;
|
|
|
|
use crate::{
|
|
dd,
|
|
dmm,
|
|
dms,
|
|
plus, //xpin
|
|
utm,
|
|
Coordinate,
|
|
Error,
|
|
LatLon,
|
|
};
|
|
|
|
pub struct Coordinates {
|
|
pub latlon: LatLon,
|
|
|
|
pub dd: dd::Coordinate,
|
|
pub dms: dms::Coordinate,
|
|
pub dmm: dmm::Coordinate,
|
|
pub utm: utm::Coordinate,
|
|
// pub xpin: xpin::Xpin,
|
|
pub plus: plus::Coordinate,
|
|
}
|
|
|
|
impl TryFrom<LatLon> for Coordinates {
|
|
type Error = Error;
|
|
|
|
fn try_from(latlon: LatLon) -> Result<Self, Self::Error> {
|
|
Ok(Self {
|
|
latlon,
|
|
dd: dd::Coordinate::try_from(latlon)?,
|
|
dms: dms::Coordinate::try_from(latlon)?,
|
|
dmm: dmm::Coordinate::try_from(latlon)?,
|
|
utm: utm::Coordinate::try_from(latlon)?,
|
|
plus: plus::Coordinate::try_from(latlon)?,
|
|
})
|
|
}
|
|
}
|
|
|
|
impl TryFrom<&crate::Coordinate> for Coordinates {
|
|
type Error = Error;
|
|
|
|
fn try_from(value: &crate::Coordinate) -> Result<Self, Self::Error> {
|
|
Self::try_from(LatLon::from(value))
|
|
}
|
|
}
|
|
|
|
impl TryFrom<crate::Coordinate> for Coordinates {
|
|
type Error = Error;
|
|
|
|
fn try_from(value: crate::Coordinate) -> Result<Self, Self::Error> {
|
|
Self::try_from(&value)
|
|
}
|
|
}
|
|
|
|
impl FromStr for Coordinates {
|
|
type Err = Error;
|
|
|
|
fn from_str(i: &str) -> Result<Self, Self::Err> {
|
|
Self::try_from(LatLon::from(&Coordinate::from_str(i)?))
|
|
}
|
|
}
|