27 lines
696 B
Rust
Raw Normal View History

2023-02-25 14:49:09 -05:00
use std::str::FromStr;
2023-02-25 11:14:25 -05:00
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
extern "C" {
2023-02-25 14:12:18 -05:00
// fn alert(s: &str);
#[wasm_bindgen(js_namespace = console, js_name = log)]
fn log_str(s: &str);
2023-02-25 11:14:25 -05:00
}
#[wasm_bindgen]
2023-02-25 14:49:09 -05:00
pub fn address_from_lat_lon(lat: f64, lon: f64) -> Result<String, String> {
2023-02-25 16:44:22 -05:00
this_algorithm::Address::from_lat_lon(lat, lon)
2023-02-25 14:12:18 -05:00
.map(|a| a.to_string())
.map_err(|e| e.to_string())
2023-02-25 11:14:25 -05:00
}
2023-02-25 14:12:18 -05:00
2023-02-25 14:49:09 -05:00
#[wasm_bindgen]
pub fn address_to_lat_lon(addr_str: &str) -> Result<Vec<f64>, String> {
2023-02-25 16:44:22 -05:00
this_algorithm::Address::from_str(addr_str)
2023-02-25 14:49:09 -05:00
.as_ref()
.map_err(|e| e.to_string())
2023-02-25 16:44:22 -05:00
.map(this_algorithm::Address::to_lat_lon)
2023-02-25 14:49:09 -05:00
.map(|(lat, lon)| vec![lat, lon])
}