More cleanup
This commit is contained in:
parent
b620ceec9b
commit
d1e6f536fb
14
src/lib.rs
14
src/lib.rs
@ -47,7 +47,7 @@ pub enum Error {
|
|||||||
WrongComponentCount,
|
WrongComponentCount,
|
||||||
/// No number component was found
|
/// 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")]
|
#[error("No number component")]
|
||||||
NoNumberComponent,
|
NoNumberComponent,
|
||||||
/// The empty string was given to decode
|
/// The empty string was given to decode
|
||||||
@ -156,11 +156,6 @@ impl Address<'_> {
|
|||||||
v0::UnpackedCellID::from(CellID(cellid_u64)).into()
|
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
|
// Parses an address v0 given the number and word components
|
||||||
fn parse_v0(number: Number, word_components: &[&str]) -> Result<Self, Error> {
|
fn parse_v0(number: Number, word_components: &[&str]) -> Result<Self, Error> {
|
||||||
if !(V0_MIN_NUMBER..=V0_MAX_NUMBER).contains(&number) {
|
if !(V0_MIN_NUMBER..=V0_MAX_NUMBER).contains(&number) {
|
||||||
@ -198,16 +193,17 @@ impl Address<'_> {
|
|||||||
|
|
||||||
/// Get the address as a [`CellID`] value
|
/// Get the address as a [`CellID`] value
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn as_cell_id(&self) -> CellID {
|
pub fn as_cellid(&self) -> CellID {
|
||||||
match self.version {
|
match self.version {
|
||||||
Version::V0 => UnpackedCellID::from(self).into(),
|
Version::V0 => UnpackedCellID::from(self).into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the address as a latitude and longitude `f64` value
|
||||||
// TODO: Test this
|
// TODO: Test this
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn to_lat_lon(&self) -> (f64, f64) {
|
pub fn as_lat_lon(&self) -> (f64, f64) {
|
||||||
let lat_lng = LatLng::from(self.as_cell_id());
|
let lat_lng = LatLng::from(self.as_cellid());
|
||||||
(lat_lng.lat.deg(), lat_lng.lng.deg())
|
(lat_lng.lat.deg(), lat_lng.lng.deg())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ fn test_invalid_lat_lon() {
|
|||||||
fn test_cellid_translation() {
|
fn test_cellid_translation() {
|
||||||
for (idx, entry) in test_events().iter().enumerate() {
|
for (idx, entry) in test_events().iter().enumerate() {
|
||||||
let addr = Address::from_lat_lon(entry.lat, entry.lon).unwrap();
|
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}");
|
eprintln!("Testing word {idx}");
|
||||||
|
|
||||||
|
@ -2,12 +2,11 @@ use std::str::FromStr;
|
|||||||
|
|
||||||
use wasm_bindgen::prelude::*;
|
use wasm_bindgen::prelude::*;
|
||||||
|
|
||||||
#[wasm_bindgen]
|
// #[wasm_bindgen]
|
||||||
extern "C" {
|
// extern "C" {
|
||||||
// fn alert(s: &str);
|
// #[wasm_bindgen(js_namespace = console, js_name = log)]
|
||||||
#[wasm_bindgen(js_namespace = console, js_name = log)]
|
// fn log_str(s: &str);
|
||||||
fn log_str(s: &str);
|
// }
|
||||||
}
|
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn address_from_lat_lon(lat: f64, lon: f64) -> Result<String, String> {
|
pub fn address_from_lat_lon(lat: f64, lon: f64) -> Result<String, String> {
|
||||||
@ -21,6 +20,6 @@ pub fn address_to_lat_lon(addr_str: &str) -> Result<Vec<f64>, String> {
|
|||||||
this_algorithm::Address::from_str(addr_str)
|
this_algorithm::Address::from_str(addr_str)
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map_err(|e| e.to_string())
|
.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])
|
.map(|(lat, lon)| vec![lat, lon])
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ async fn get_coords(address: Option<String>) -> Result<Json<Coords>, ApiError> {
|
|||||||
Address::from_str(&address)
|
Address::from_str(&address)
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map_err(Into::into)
|
.map_err(Into::into)
|
||||||
.map(Address::to_lat_lon)
|
.map(Address::as_lat_lon)
|
||||||
.map(Coords::from)
|
.map(Coords::from)
|
||||||
.map(Json)
|
.map(Json)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user