From c53f00ea4acbcc3bbb5339ed3f9226c61a5b0788 Mon Sep 17 00:00:00 2001 From: Austen Adler Date: Tue, 18 Apr 2023 21:14:43 -0400 Subject: [PATCH] Impl From for Coordinate --- spatial-coordinate-systems/src/lib.rs | 6 ++++++ xpin-wasm/src/lib.rs | 5 +---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/spatial-coordinate-systems/src/lib.rs b/spatial-coordinate-systems/src/lib.rs index 8424321..5ac6280 100644 --- a/spatial-coordinate-systems/src/lib.rs +++ b/spatial-coordinate-systems/src/lib.rs @@ -126,6 +126,12 @@ impl Coordinate { } } +impl From for Coordinate { + fn from(latlon: LatLon) -> Self { + Self::DD(dd::Coordinate::from(latlon)) + } +} + impl From<&Coordinate> for LatLon { fn from(value: &Coordinate) -> LatLon { match value { diff --git a/xpin-wasm/src/lib.rs b/xpin-wasm/src/lib.rs index dc561bc..f4a1297 100644 --- a/xpin-wasm/src/lib.rs +++ b/xpin-wasm/src/lib.rs @@ -52,10 +52,7 @@ impl EncodedAddress { .map_err(|e| e.to_string())? .as_lat_lon(); - - // TODO: Do not allocate a string here - let src_coords = - Coordinate::from_str(&format!("{}, {}", lat, lon)).map_err(|e| e.to_string())?; + let src_coords = Coordinate::from(LatLon::new(lat, lon).map_err(|e| e.to_string())?); Self::try_from(src_coords) }