From d1e6f536fb7003ad669ee8d44c4989659c7e9a8e Mon Sep 17 00:00:00 2001 From: Austen Adler Date: Tue, 28 Feb 2023 09:20:06 -0500 Subject: [PATCH] More cleanup --- src/lib.rs | 14 +++++--------- tests/algorithm.rs | 2 +- this_algorithm-wasm/src/lib.rs | 13 ++++++------- web/src/main.rs | 2 +- 4 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 0531ca0..13bdc6c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -47,7 +47,7 @@ pub enum Error { WrongComponentCount, /// No number component was found /// - /// See [`Algorithm::from_str`] for the possible position of the number component + /// See [`Address::from_str`] for the possible position of the number component #[error("No number component")] NoNumberComponent, /// The empty string was given to decode @@ -156,11 +156,6 @@ impl Address<'_> { v0::UnpackedCellID::from(CellID(cellid_u64)).into() } - // /// Decodes an address to latitude and longitude - // pub fn to_lat_lon(&self) -> (f64, f64) { - // let cellid = self.as_cell_id(); - // } - // Parses an address v0 given the number and word components fn parse_v0(number: Number, word_components: &[&str]) -> Result { if !(V0_MIN_NUMBER..=V0_MAX_NUMBER).contains(&number) { @@ -198,16 +193,17 @@ impl Address<'_> { /// Get the address as a [`CellID`] value #[must_use] - pub fn as_cell_id(&self) -> CellID { + pub fn as_cellid(&self) -> CellID { match self.version { Version::V0 => UnpackedCellID::from(self).into(), } } + /// Get the address as a latitude and longitude `f64` value // TODO: Test this #[must_use] - pub fn to_lat_lon(&self) -> (f64, f64) { - let lat_lng = LatLng::from(self.as_cell_id()); + pub fn as_lat_lon(&self) -> (f64, f64) { + let lat_lng = LatLng::from(self.as_cellid()); (lat_lng.lat.deg(), lat_lng.lng.deg()) } } diff --git a/tests/algorithm.rs b/tests/algorithm.rs index 5b242f2..f3042e5 100644 --- a/tests/algorithm.rs +++ b/tests/algorithm.rs @@ -23,7 +23,7 @@ fn test_invalid_lat_lon() { fn test_cellid_translation() { for (idx, entry) in test_events().iter().enumerate() { let addr = Address::from_lat_lon(entry.lat, entry.lon).unwrap(); - let addr_cellid = addr.as_cell_id(); + let addr_cellid = addr.as_cellid(); eprintln!("Testing word {idx}"); diff --git a/this_algorithm-wasm/src/lib.rs b/this_algorithm-wasm/src/lib.rs index 682eca5..cf38072 100644 --- a/this_algorithm-wasm/src/lib.rs +++ b/this_algorithm-wasm/src/lib.rs @@ -2,12 +2,11 @@ use std::str::FromStr; use wasm_bindgen::prelude::*; -#[wasm_bindgen] -extern "C" { - // fn alert(s: &str); - #[wasm_bindgen(js_namespace = console, js_name = log)] - fn log_str(s: &str); -} +// #[wasm_bindgen] +// extern "C" { +// #[wasm_bindgen(js_namespace = console, js_name = log)] +// fn log_str(s: &str); +// } #[wasm_bindgen] pub fn address_from_lat_lon(lat: f64, lon: f64) -> Result { @@ -21,6 +20,6 @@ pub fn address_to_lat_lon(addr_str: &str) -> Result, String> { this_algorithm::Address::from_str(addr_str) .as_ref() .map_err(|e| e.to_string()) - .map(this_algorithm::Address::to_lat_lon) + .map(this_algorithm::Address::as_lat_lon) .map(|(lat, lon)| vec![lat, lon]) } diff --git a/web/src/main.rs b/web/src/main.rs index a1634fd..ef312f6 100644 --- a/web/src/main.rs +++ b/web/src/main.rs @@ -39,7 +39,7 @@ async fn get_coords(address: Option) -> Result, ApiError> { Address::from_str(&address) .as_ref() .map_err(Into::into) - .map(Address::to_lat_lon) + .map(Address::as_lat_lon) .map(Coords::from) .map(Json) }