This commit is contained in:
Austen Adler 2023-02-25 16:44:22 -05:00
parent d8958e0645
commit 0546720e3d
5 changed files with 9 additions and 6 deletions

Binary file not shown.

View File

@ -29,9 +29,9 @@ pub const V0_MIN_NUMBER: u32 = 1;
#[derive(Error, Debug, Eq, PartialEq)]
pub enum Error {
#[error("Word does not exist")]
#[error("Word does not exist: {0}")]
WordDoesNotExist(String),
#[error("Invalid version")]
#[error("Invalid version: {0}")]
InvalidVersion(u8),
#[error("Unimplemented version")]
UnimplementedVersion(Version),

View File

@ -1,3 +1,4 @@
#![allow(dead_code)]
use std::fs::File;
use csv::ReaderBuilder;

View File

@ -7,6 +7,8 @@ import init, { address_from_lat_lon, address_to_lat_lon } from "./pkg/this_algor
init().then(() => {
let updateEncode = () => {
if (!encodeAddressLat.value || !encodeAddressLon.value) {
encodeAddressResult.value = "";
encodeAddressError.textContent = "";
return;
}
@ -17,6 +19,7 @@ init().then(() => {
encodeAddressResult.value = address_from_lat_lon(lat, lon);
encodeAddressError.textContent = "";
} catch(e) {
encodeAddressResult.value = "";
encodeAddressError.textContent = e;
}
};

View File

@ -1,6 +1,5 @@
use std::str::FromStr;
use this_algorithm::Address;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
@ -12,16 +11,16 @@ extern "C" {
#[wasm_bindgen]
pub fn address_from_lat_lon(lat: f64, lon: f64) -> Result<String, String> {
Address::from_lat_lon(lat, lon)
this_algorithm::Address::from_lat_lon(lat, lon)
.map(|a| a.to_string())
.map_err(|e| e.to_string())
}
#[wasm_bindgen]
pub fn address_to_lat_lon(addr_str: &str) -> Result<Vec<f64>, String> {
Address::from_str(addr_str)
this_algorithm::Address::from_str(addr_str)
.as_ref()
.map_err(|e| e.to_string())
.map(Address::to_lat_lon)
.map(this_algorithm::Address::to_lat_lon)
.map(|(lat, lon)| vec![lat, lon])
}