diff --git a/Cargo.lock b/Cargo.lock index 78f7cfa..645fc2a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1372,6 +1372,7 @@ version = "0.1.0" dependencies = [ "nom", "pluscodes", + "serde", "thiserror", "url", "utm", diff --git a/spatial-coordinate-systems/Cargo.toml b/spatial-coordinate-systems/Cargo.toml index 8a4d8ee..c4dce3e 100644 --- a/spatial-coordinate-systems/Cargo.toml +++ b/spatial-coordinate-systems/Cargo.toml @@ -7,6 +7,7 @@ edition = "2021" [features] wasm_bindgen = ["dep:wasm-bindgen"] +serde = ["dep:serde"] [dependencies] # Excluding because rustc-serialize does not work with wasm @@ -28,3 +29,4 @@ thiserror = "1.0.38" url = "2.3.1" wasm-bindgen={version="0.2",optional=true} +serde={version="1",optional=true,features=["derive"]} diff --git a/spatial-coordinate-systems/src/latlon.rs b/spatial-coordinate-systems/src/latlon.rs index 5a52d10..363140f 100644 --- a/spatial-coordinate-systems/src/latlon.rs +++ b/spatial-coordinate-systems/src/latlon.rs @@ -1,6 +1,8 @@ +#[cfg(feature = "serde")] +use serde::{Deserialize, Serialize}; +use std::fmt; #[cfg(feature = "wasm_bindgen")] use wasm_bindgen::prelude::*; -use std::fmt; use nom::{ character::complete::space0, @@ -15,6 +17,7 @@ use crate::{ }; #[cfg_attr(feature = "wasm_bindgen", wasm_bindgen(getter_with_clone))] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[derive(PartialEq, Debug, Clone, Copy)] pub struct LatLon { lat: f64, diff --git a/spatial-coordinate-systems/src/urls.rs b/spatial-coordinate-systems/src/urls.rs index b2fca01..cef66a6 100644 --- a/spatial-coordinate-systems/src/urls.rs +++ b/spatial-coordinate-systems/src/urls.rs @@ -1,5 +1,3 @@ -#[cfg(feature = "wasm_bindgen")] -use wasm_bindgen::prelude::*; use crate::{common::parse_f64, Error, LatLon}; use nom::{ branch::alt, @@ -10,13 +8,18 @@ use nom::{ sequence::tuple, IResult, }; +#[cfg(feature = "serde")] +use serde::{Deserialize, Serialize}; use std::str::FromStr; use url::Url; +#[cfg(feature = "wasm_bindgen")] +use wasm_bindgen::prelude::*; // TODO: Set a reasonable OSM zoom level const OPENSTREETMAP_ZOOM_LEVEL: u8 = 19; #[cfg_attr(feature = "wasm_bindgen", wasm_bindgen(getter_with_clone))] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[derive(PartialEq, Debug, Clone)] pub struct CoordinateUrls { // TODO: These should be getters only