Add serde derive features to spatial-coordinate-systems

This commit is contained in:
Austen Adler 2023-03-28 23:34:05 -04:00
parent f687c45b6d
commit 8dece0b547
4 changed files with 12 additions and 3 deletions

1
Cargo.lock generated
View File

@ -1372,6 +1372,7 @@ version = "0.1.0"
dependencies = [ dependencies = [
"nom", "nom",
"pluscodes", "pluscodes",
"serde",
"thiserror", "thiserror",
"url", "url",
"utm", "utm",

View File

@ -7,6 +7,7 @@ edition = "2021"
[features] [features]
wasm_bindgen = ["dep:wasm-bindgen"] wasm_bindgen = ["dep:wasm-bindgen"]
serde = ["dep:serde"]
[dependencies] [dependencies]
# Excluding because rustc-serialize does not work with wasm # Excluding because rustc-serialize does not work with wasm
@ -28,3 +29,4 @@ thiserror = "1.0.38"
url = "2.3.1" 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"]}

View File

@ -1,6 +1,8 @@
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use std::fmt;
#[cfg(feature = "wasm_bindgen")] #[cfg(feature = "wasm_bindgen")]
use wasm_bindgen::prelude::*; use wasm_bindgen::prelude::*;
use std::fmt;
use nom::{ use nom::{
character::complete::space0, character::complete::space0,
@ -15,6 +17,7 @@ use crate::{
}; };
#[cfg_attr(feature = "wasm_bindgen", wasm_bindgen(getter_with_clone))] #[cfg_attr(feature = "wasm_bindgen", wasm_bindgen(getter_with_clone))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(PartialEq, Debug, Clone, Copy)] #[derive(PartialEq, Debug, Clone, Copy)]
pub struct LatLon { pub struct LatLon {
lat: f64, lat: f64,

View File

@ -1,5 +1,3 @@
#[cfg(feature = "wasm_bindgen")]
use wasm_bindgen::prelude::*;
use crate::{common::parse_f64, Error, LatLon}; use crate::{common::parse_f64, Error, LatLon};
use nom::{ use nom::{
branch::alt, branch::alt,
@ -10,13 +8,18 @@ use nom::{
sequence::tuple, sequence::tuple,
IResult, IResult,
}; };
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use std::str::FromStr; use std::str::FromStr;
use url::Url; use url::Url;
#[cfg(feature = "wasm_bindgen")]
use wasm_bindgen::prelude::*;
// 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;
#[cfg_attr(feature = "wasm_bindgen", wasm_bindgen(getter_with_clone))] #[cfg_attr(feature = "wasm_bindgen", wasm_bindgen(getter_with_clone))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(PartialEq, Debug, Clone)] #[derive(PartialEq, Debug, Clone)]
pub struct CoordinateUrls { pub struct CoordinateUrls {
// TODO: These should be getters only // TODO: These should be getters only