Skip to content
This repository was archived by the owner on May 20, 2024. It is now read-only.

Commit 6486b0a

Browse files
committed
Update simd-json-derive
1 parent b166f91 commit 6486b0a

File tree

8 files changed

+399
-89
lines changed

8 files changed

+399
-89
lines changed

src/canada.rs

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,56 @@ use std::collections::BTreeMap as Map;
66
pub type Canada = FeatureCollection;
77

88
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9-
#[cfg_attr(feature = "serde", serde(deny_unknown_fields))]
10-
#[cfg_attr(feature = "lib-simd-json", derive(simd_json_derive::Serialize))]
9+
#[cfg_attr(
10+
any(feature = "serde", feature = "lib-simd-json"),
11+
serde(deny_unknown_fields)
12+
)]
13+
#[cfg_attr(
14+
feature = "lib-simd-json",
15+
derive(simd_json_derive::Serialize, simd_json_derive::Deserialize)
16+
)]
1117
pub struct FeatureCollection {
12-
#[cfg_attr(feature = "serde", serde(rename = "type"))]
18+
#[cfg_attr(
19+
any(feature = "serde", feature = "lib-simd-json"),
20+
serde(rename = "type")
21+
)]
1322
pub obj_type: ObjType,
1423
pub features: Vec<Feature>,
1524
}
1625

1726
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
18-
#[cfg_attr(feature = "serde", serde(deny_unknown_fields))]
19-
#[cfg_attr(feature = "lib-simd-json", derive(simd_json_derive::Serialize))]
27+
#[cfg_attr(
28+
any(feature = "serde", feature = "lib-simd-json"),
29+
serde(deny_unknown_fields)
30+
)]
31+
#[cfg_attr(
32+
feature = "lib-simd-json",
33+
derive(simd_json_derive::Serialize, simd_json_derive::Deserialize)
34+
)]
2035
pub struct Feature {
21-
#[cfg_attr(feature = "serde", serde(rename = "type"))]
36+
#[cfg_attr(
37+
any(feature = "serde", feature = "lib-simd-json"),
38+
serde(rename = "type")
39+
)]
2240
pub obj_type: ObjType,
2341
pub properties: Map<String, String>,
2442
pub geometry: Geometry,
2543
}
2644

2745
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
28-
#[cfg_attr(feature = "serde", serde(deny_unknown_fields))]
29-
#[cfg_attr(feature = "lib-simd-json", derive(simd_json_derive::Serialize))]
46+
#[cfg_attr(
47+
any(feature = "serde", feature = "lib-simd-json"),
48+
serde(deny_unknown_fields)
49+
)]
50+
#[cfg_attr(
51+
feature = "lib-simd-json",
52+
derive(simd_json_derive::Serialize, simd_json_derive::Deserialize)
53+
)]
3054
pub struct Geometry {
31-
#[cfg_attr(feature = "serde", serde(rename = "type"))]
55+
#[cfg_attr(
56+
any(feature = "serde", feature = "lib-simd-json"),
57+
serde(rename = "type")
58+
)]
3259
pub obj_type: ObjType,
3360
pub coordinates: Vec<Vec<(Latitude, Longitude)>>,
3461
}

src/color.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use serde::de::{self, Deserialize, Deserializer, Unexpected};
1212
#[cfg(feature = "serde")]
1313
use serde::ser::{Serialize, Serializer};
1414

15-
#[derive(Clone, Copy)]
15+
#[derive(Clone, Copy, Debug)]
1616
pub struct Color(u32);
1717

1818
#[cfg(any(feature = "serde", feature = "lib-rustc-serialize"))]
@@ -99,6 +99,29 @@ impl<'de> Deserialize<'de> for Color {
9999
}
100100
}
101101

102+
#[cfg(feature = "lib-simd-json")]
103+
impl<'input> ::simd_json_derive::Deserialize<'input> for Color {
104+
#[inline]
105+
fn from_tape(tape: &mut ::simd_json_derive::Tape<'input>) -> simd_json::Result<Self>
106+
where
107+
Self: std::marker::Sized + 'input,
108+
{
109+
if let Some(::simd_json::Node::String(s)) = tape.next() {
110+
if let Ok(hex) = u32::from_str_radix(s, 16) {
111+
Ok(Color(hex))
112+
} else {
113+
dbg!(Err(::simd_json::Error::generic(
114+
simd_json::ErrorType::ExpectedString,
115+
)))
116+
}
117+
} else {
118+
dbg!(Err(::simd_json::Error::generic(
119+
simd_json::ErrorType::ExpectedString,
120+
)))
121+
}
122+
}
123+
}
124+
102125
#[cfg(feature = "lib-rustc-serialize")]
103126
impl Encodable for Color {
104127
fn encode<S>(&self, s: &mut S) -> Result<(), S::Error>

src/copy/citm_catalog.rs

Lines changed: 54 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,18 @@ use std::collections::BTreeMap as Map;
66
use crate::empty;
77
use crate::prim_str::PrimStr;
88

9-
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
109
#[cfg_attr(
11-
feature = "serde",
10+
any(feature = "serde", feature = "lib-simd-json"),
11+
derive(Serialize, Deserialize)
12+
)]
13+
#[cfg_attr(
14+
any(feature = "serde", feature = "lib-simd-json"),
1215
serde(deny_unknown_fields, rename_all = "camelCase")
1316
)]
14-
#[cfg_attr(feature = "lib-simd-json", derive(simd_json_derive::Serialize))]
17+
#[cfg_attr(
18+
feature = "lib-simd-json",
19+
derive(simd_json_derive::Serialize, simd_json_derive::Deserialize)
20+
)]
1521
pub struct CitmCatalog {
1622
pub area_names: Map<IdStr, String>,
1723
pub audience_sub_category_names: Map<IdStr, String>,
@@ -29,12 +35,18 @@ pub struct CitmCatalog {
2935
pub type Id = u32;
3036
pub type IdStr = PrimStr<u32>;
3137

32-
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3338
#[cfg_attr(
34-
feature = "serde",
39+
any(feature = "serde", feature = "lib-simd-json"),
40+
derive(Serialize, Deserialize)
41+
)]
42+
#[cfg_attr(
43+
any(feature = "serde", feature = "lib-simd-json"),
3544
serde(deny_unknown_fields, rename_all = "camelCase")
3645
)]
37-
#[cfg_attr(feature = "lib-simd-json", derive(simd_json_derive::Serialize))]
46+
#[cfg_attr(
47+
feature = "lib-simd-json",
48+
derive(simd_json_derive::Serialize, simd_json_derive::Deserialize)
49+
)]
3850
pub struct Event {
3951
pub description: (),
4052
pub id: Id,
@@ -46,12 +58,18 @@ pub struct Event {
4658
pub topic_ids: Vec<Id>,
4759
}
4860

49-
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5061
#[cfg_attr(
51-
feature = "serde",
62+
any(feature = "serde", feature = "lib-simd-json"),
63+
derive(Serialize, Deserialize)
64+
)]
65+
#[cfg_attr(
66+
any(feature = "serde", feature = "lib-simd-json"),
5267
serde(deny_unknown_fields, rename_all = "camelCase")
5368
)]
54-
#[cfg_attr(feature = "lib-simd-json", derive(simd_json_derive::Serialize))]
69+
#[cfg_attr(
70+
feature = "lib-simd-json",
71+
derive(simd_json_derive::Serialize, simd_json_derive::Deserialize)
72+
)]
5573
pub struct Performance {
5674
pub event_id: Id,
5775
pub id: Id,
@@ -64,35 +82,53 @@ pub struct Performance {
6482
pub venue_code: String,
6583
}
6684

67-
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6885
#[cfg_attr(
69-
feature = "serde",
86+
any(feature = "serde", feature = "lib-simd-json"),
87+
derive(Serialize, Deserialize)
88+
)]
89+
#[cfg_attr(
90+
any(feature = "serde", feature = "lib-simd-json"),
7091
serde(deny_unknown_fields, rename_all = "camelCase")
7192
)]
72-
#[cfg_attr(feature = "lib-simd-json", derive(simd_json_derive::Serialize))]
93+
#[cfg_attr(
94+
feature = "lib-simd-json",
95+
derive(simd_json_derive::Serialize, simd_json_derive::Deserialize)
96+
)]
7397
pub struct Price {
7498
pub amount: u32,
7599
pub audience_sub_category_id: Id,
76100
pub seat_category_id: Id,
77101
}
78102

79-
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
80103
#[cfg_attr(
81-
feature = "serde",
104+
any(feature = "serde", feature = "lib-simd-json"),
105+
derive(Serialize, Deserialize)
106+
)]
107+
#[cfg_attr(
108+
any(feature = "serde", feature = "lib-simd-json"),
82109
serde(deny_unknown_fields, rename_all = "camelCase")
83110
)]
84-
#[cfg_attr(feature = "lib-simd-json", derive(simd_json_derive::Serialize))]
111+
#[cfg_attr(
112+
feature = "lib-simd-json",
113+
derive(simd_json_derive::Serialize, simd_json_derive::Deserialize)
114+
)]
85115
pub struct SeatCategory {
86116
pub areas: Vec<Area>,
87117
pub seat_category_id: Id,
88118
}
89119

90-
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
91120
#[cfg_attr(
92-
feature = "serde",
121+
any(feature = "serde", feature = "lib-simd-json"),
122+
derive(Serialize, Deserialize)
123+
)]
124+
#[cfg_attr(
125+
any(feature = "serde", feature = "lib-simd-json"),
93126
serde(deny_unknown_fields, rename_all = "camelCase")
94127
)]
95-
#[cfg_attr(feature = "lib-simd-json", derive(simd_json_derive::Serialize))]
128+
#[cfg_attr(
129+
feature = "lib-simd-json",
130+
derive(simd_json_derive::Serialize, simd_json_derive::Deserialize)
131+
)]
96132
pub struct Area {
97133
pub area_id: Id,
98134
pub block_ids: empty::Array,

0 commit comments

Comments
 (0)