Do not duplicate structs in xpin-wasm
This commit is contained in:
parent
8dece0b547
commit
aad626d3fc
31
Cargo.lock
generated
31
Cargo.lock
generated
@ -504,6 +504,12 @@ dependencies = [
|
|||||||
"unicode-segmentation",
|
"unicode-segmentation",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "heck"
|
||||||
|
version = "0.4.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hermit-abi"
|
name = "hermit-abi"
|
||||||
version = "0.1.19"
|
version = "0.1.19"
|
||||||
@ -1373,6 +1379,7 @@ dependencies = [
|
|||||||
"nom",
|
"nom",
|
||||||
"pluscodes",
|
"pluscodes",
|
||||||
"serde",
|
"serde",
|
||||||
|
"strum",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"url",
|
"url",
|
||||||
"utm",
|
"utm",
|
||||||
@ -1426,13 +1433,35 @@ version = "0.4.18"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0"
|
checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"heck",
|
"heck 0.3.3",
|
||||||
"proc-macro-error",
|
"proc-macro-error",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 1.0.109",
|
"syn 1.0.109",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "strum"
|
||||||
|
version = "0.24.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "063e6045c0e62079840579a7e47a355ae92f60eb74daaf156fb1e84ba164e63f"
|
||||||
|
dependencies = [
|
||||||
|
"strum_macros",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "strum_macros"
|
||||||
|
version = "0.24.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59"
|
||||||
|
dependencies = [
|
||||||
|
"heck 0.4.1",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"rustversion",
|
||||||
|
"syn 1.0.109",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "1.0.109"
|
version = "1.0.109"
|
||||||
|
@ -30,3 +30,4 @@ url = "2.3.1"
|
|||||||
|
|
||||||
wasm-bindgen={version="0.2",optional=true}
|
wasm-bindgen={version="0.2",optional=true}
|
||||||
serde={version="1",optional=true,features=["derive"]}
|
serde={version="1",optional=true,features=["derive"]}
|
||||||
|
strum={version="0.24",features=["derive"]}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
#[cfg(feature = "wasm_bindgen")]
|
#[cfg(feature = "wasm_bindgen")]
|
||||||
use wasm_bindgen::prelude::*;
|
use wasm_bindgen::prelude::wasm_bindgen;
|
||||||
|
|
||||||
use nom::{
|
use nom::{
|
||||||
character::complete::space0,
|
character::complete::space0,
|
||||||
|
@ -9,8 +9,11 @@ pub mod plus;
|
|||||||
pub mod urls;
|
pub mod urls;
|
||||||
pub mod utm;
|
pub mod utm;
|
||||||
pub use error::Error;
|
pub use error::Error;
|
||||||
|
use strum::EnumDiscriminants;
|
||||||
// pub mod xpin;
|
// pub mod xpin;
|
||||||
mod error;
|
mod error;
|
||||||
|
#[cfg(feature = "wasm_bindgen")]
|
||||||
|
use wasm_bindgen::prelude::wasm_bindgen;
|
||||||
|
|
||||||
use nom::{
|
use nom::{
|
||||||
branch::alt,
|
branch::alt,
|
||||||
@ -21,6 +24,7 @@ use nom::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub use latlon::LatLon;
|
pub use latlon::LatLon;
|
||||||
|
use strum::EnumString;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub enum Direction {
|
pub enum Direction {
|
||||||
@ -52,7 +56,13 @@ impl Direction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone, EnumDiscriminants)]
|
||||||
|
#[cfg_attr(
|
||||||
|
feature = "wasm_bindgen",
|
||||||
|
strum_discriminants(wasm_bindgen(getter_with_clone))
|
||||||
|
)]
|
||||||
|
#[strum_discriminants(derive(EnumString))]
|
||||||
|
#[strum_discriminants(name(CoordinateType))]
|
||||||
pub enum Coordinate {
|
pub enum Coordinate {
|
||||||
DD(dd::Coordinate),
|
DD(dd::Coordinate),
|
||||||
DMS(dms::Coordinate),
|
DMS(dms::Coordinate),
|
||||||
@ -62,16 +72,6 @@ pub enum Coordinate {
|
|||||||
Plus(plus::Coordinate),
|
Plus(plus::Coordinate),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
|
||||||
pub enum CoordinateType {
|
|
||||||
DD,
|
|
||||||
DMS,
|
|
||||||
DMM,
|
|
||||||
UTM,
|
|
||||||
// Xpin,
|
|
||||||
Plus,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Coordinate {
|
impl Coordinate {
|
||||||
pub fn parse(i: &str) -> IResult<&str, Self> {
|
pub fn parse(i: &str) -> IResult<&str, Self> {
|
||||||
map(
|
map(
|
||||||
|
@ -13,7 +13,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
#[cfg(feature = "wasm_bindgen")]
|
#[cfg(feature = "wasm_bindgen")]
|
||||||
use wasm_bindgen::prelude::*;
|
use wasm_bindgen::prelude::wasm_bindgen;
|
||||||
|
|
||||||
// TODO: Set a reasonable OSM zoom level
|
// TODO: Set a reasonable OSM zoom level
|
||||||
const OPENSTREETMAP_ZOOM_LEVEL: u8 = 19;
|
const OPENSTREETMAP_ZOOM_LEVEL: u8 = 19;
|
||||||
|
@ -1,46 +1,9 @@
|
|||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use spatial_coordinate_systems::{urls::CoordinateUrls, Coordinate, LatLon};
|
use spatial_coordinate_systems::{urls::CoordinateUrls, Coordinate, CoordinateType, LatLon};
|
||||||
use wasm_bindgen::prelude::*;
|
use wasm_bindgen::prelude::*;
|
||||||
use xpin::Address;
|
use xpin::Address;
|
||||||
|
|
||||||
#[wasm_bindgen]
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
|
||||||
pub enum CoordinateType {
|
|
||||||
DD,
|
|
||||||
DMS,
|
|
||||||
DMM,
|
|
||||||
UTM,
|
|
||||||
// Xpin,
|
|
||||||
Plus,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<CoordinateType> for spatial_coordinate_systems::CoordinateType {
|
|
||||||
fn from(val: CoordinateType) -> Self {
|
|
||||||
match val {
|
|
||||||
CoordinateType::DD => Self::DD,
|
|
||||||
CoordinateType::DMS => Self::DMS,
|
|
||||||
CoordinateType::DMM => Self::DMM,
|
|
||||||
CoordinateType::UTM => Self::UTM,
|
|
||||||
// CoordinateType::Xpin => Self::Xpin,
|
|
||||||
CoordinateType::Plus => Self::Plus,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<spatial_coordinate_systems::CoordinateType> for CoordinateType {
|
|
||||||
fn from(value: spatial_coordinate_systems::CoordinateType) -> CoordinateType {
|
|
||||||
match value {
|
|
||||||
spatial_coordinate_systems::CoordinateType::DD => Self::DD,
|
|
||||||
spatial_coordinate_systems::CoordinateType::DMS => Self::DMS,
|
|
||||||
spatial_coordinate_systems::CoordinateType::DMM => Self::DMM,
|
|
||||||
spatial_coordinate_systems::CoordinateType::UTM => Self::UTM,
|
|
||||||
// spatial_coordinate_systems::CoordinateType::Xpin => Self::Xpin,
|
|
||||||
spatial_coordinate_systems::CoordinateType::Plus => Self::Plus,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[wasm_bindgen(getter_with_clone)]
|
#[wasm_bindgen(getter_with_clone)]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct EncodedAddress {
|
pub struct EncodedAddress {
|
||||||
@ -186,26 +149,9 @@ impl TryFrom<&'_ Address<'_>> for EncodedAddress {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[wasm_bindgen(getter_with_clone)]
|
|
||||||
// #[derive(Debug, Clone)]
|
|
||||||
// pub struct CoordinateUrls {
|
|
||||||
// // TODO: These should be getters only
|
|
||||||
// pub google_maps: String,
|
|
||||||
// pub openstreetmap: String,
|
|
||||||
// }
|
|
||||||
|
|
||||||
// impl From<spatial_coordinate_systems::urls::CoordinateUrls> for CoordinateUrls {
|
|
||||||
// fn from(value: spatial_coordinate_systems::urls::CoordinateUrls) -> Self {
|
|
||||||
// Self {
|
|
||||||
// google_maps: value.google_maps,
|
|
||||||
// openstreetmap: value.openstreetmap,
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
// use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_general() {
|
fn test_general() {
|
||||||
|
Loading…
Reference in New Issue
Block a user