Skip to content

Commit 7869be5

Browse files
authored
Merge pull request #31 from arcnmx/serdetuple
remove serde_tuple
2 parents 94a2189 + c65b759 commit 7869be5

File tree

3 files changed

+60
-11
lines changed

3 files changed

+60
-11
lines changed

model/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ name = "gw2lib_model"
1515
path = "src/lib.rs"
1616

1717
[dependencies]
18-
serde_tuple = "0.5.0"
1918
urlencoding = "2.1.2"
2019

2120
[dependencies.either]

model/src/maps/continents.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,28 @@ mod floors;
33
use std::collections::BTreeSet;
44

55
use serde::{ser::SerializeSeq, Deserialize, Deserializer, Serialize, Serializer};
6-
use serde_tuple::{Deserialize_tuple, Serialize_tuple};
76

87
pub use crate::maps::continents::floors::*;
98
use crate::{BulkEndpoint, Endpoint, EndpointWithId};
109

1110
pub type ContinentId = u32;
1211

13-
#[derive(Clone, Debug, Ord, PartialOrd, Eq, PartialEq, Serialize_tuple, Deserialize_tuple)]
14-
#[cfg_attr(test, serde(deny_unknown_fields))]
12+
#[derive(Clone, Debug, Ord, PartialOrd, Eq, PartialEq, Serialize, Deserialize)]
13+
#[serde(from = "[u32; 2]", into = "[u32; 2]")]
1514
pub struct Dimensions {
1615
pub width: u32,
1716
pub height: u32,
1817
}
18+
impl From<[u32; 2]> for Dimensions {
19+
fn from([width, height]: [u32; 2]) -> Self {
20+
Self { width, height }
21+
}
22+
}
23+
impl From<Dimensions> for [u32; 2] {
24+
fn from(v: Dimensions) -> Self {
25+
[v.width, v.height]
26+
}
27+
}
1928

2029
#[derive(Clone, Debug, Serialize)]
2130
#[cfg_attr(test, serde(deny_unknown_fields))]

model/src/maps/continents/floors.rs

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use std::{
44
};
55

66
use serde::{Deserialize, Serialize};
7-
use serde_tuple::{Deserialize_tuple, Serialize_tuple};
87

98
use crate::{
109
maps::{
@@ -43,26 +42,68 @@ impl Display for ContinentFloorId {
4342
}
4443
}
4544

46-
#[derive(Clone, Debug, PartialOrd, PartialEq, Serialize_tuple, Deserialize_tuple)]
47-
#[cfg_attr(test, serde(deny_unknown_fields))]
45+
#[derive(Clone, Debug, PartialOrd, PartialEq, Serialize, Deserialize)]
46+
#[serde(from = "[f32; 2]", into = "[f32; 2]")]
4847
pub struct Coordinates {
4948
pub x: f32,
5049
pub y: f32,
5150
}
51+
impl From<[f32; 2]> for Coordinates {
52+
fn from([x, y]: [f32; 2]) -> Self {
53+
Self { x, y }
54+
}
55+
}
56+
impl From<Coordinates> for [f32; 2] {
57+
fn from(v: Coordinates) -> Self {
58+
[v.x, v.y]
59+
}
60+
}
5261

53-
#[derive(Clone, Debug, PartialOrd, PartialEq, Serialize_tuple, Deserialize_tuple)]
54-
#[cfg_attr(test, serde(deny_unknown_fields))]
62+
#[derive(Clone, Debug, PartialOrd, PartialEq, Serialize, Deserialize)]
63+
#[serde(from = "[Coordinates; 2]", into = "[Coordinates; 2]")]
5564
pub struct ContinentRectangle {
5665
pub top_left: Coordinates,
5766
pub bottom_right: Coordinates,
5867
}
68+
impl<C: Into<Coordinates>> From<[C; 2]> for ContinentRectangle {
69+
fn from([top_left, bottom_right]: [C; 2]) -> Self {
70+
Self {
71+
top_left: top_left.into(),
72+
bottom_right: bottom_right.into(),
73+
}
74+
}
75+
}
76+
impl<C> From<ContinentRectangle> for [C; 2]
77+
where
78+
Coordinates: Into<C>,
79+
{
80+
fn from(v: ContinentRectangle) -> Self {
81+
[v.top_left.into(), v.bottom_right.into()]
82+
}
83+
}
5984

60-
#[derive(Clone, Debug, PartialOrd, PartialEq, Serialize_tuple, Deserialize_tuple)]
61-
#[cfg_attr(test, serde(deny_unknown_fields))]
85+
#[derive(Clone, Debug, PartialOrd, PartialEq, Serialize, Deserialize)]
86+
#[serde(from = "[Coordinates; 2]", into = "[Coordinates; 2]")]
6287
pub struct MapRectangle {
6388
pub bottom_left: Coordinates,
6489
pub top_right: Coordinates,
6590
}
91+
impl<C: Into<Coordinates>> From<[C; 2]> for MapRectangle {
92+
fn from([bottom_left, top_right]: [C; 2]) -> Self {
93+
Self {
94+
bottom_left: bottom_left.into(),
95+
top_right: top_right.into(),
96+
}
97+
}
98+
}
99+
impl<C> From<MapRectangle> for [C; 2]
100+
where
101+
Coordinates: Into<C>,
102+
{
103+
fn from(v: MapRectangle) -> Self {
104+
[v.bottom_left.into(), v.top_right.into()]
105+
}
106+
}
66107

67108
#[derive(Clone, PartialEq, Eq, PartialOrd, Debug, Serialize, Deserialize)]
68109
#[serde(rename_all = "lowercase")]

0 commit comments

Comments
 (0)