Skip to content

Commit c8bd20b

Browse files
committed
Standardize usage of serde derives somewhat.
1 parent c36ba06 commit c8bd20b

40 files changed

+113
-86
lines changed

Diff for: Cargo.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ appveyor = { service = "github", repository = "daboross/rust-screeps-api", branc
3434
# Logging
3535
log = "0.4"
3636
# Parsing
37-
serde = "1.0"
38-
serde_derive = "1.0"
37+
serde = { version = "1.0", features = ["derive"] }
3938
serde_json = "1.0"
4039
serde_ignored = "0.1"
4140
serde-tuple-vec-map = "1.0"

Diff for: src/data/errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
use crate::error;
33

44
/// JSON API error result from the server.
5-
#[derive(serde_derive::Deserialize, Clone, Eq, PartialEq, Hash, Debug)]
5+
#[derive(serde::Deserialize, Clone, Eq, PartialEq, Hash, Debug)]
66
pub struct ApiError {
77
/// The error string.
88
pub error: String,

Diff for: src/data/room_name.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
use std::borrow::Cow;
33
use std::{error, fmt, ops};
44

5+
use serde::{Deserialize, Serialize};
6+
57
/// A structure representing a room name.
68
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
79
pub struct RoomName {
@@ -249,7 +251,7 @@ impl<'a> fmt::Display for RoomNameParseError<'a> {
249251
}
250252
}
251253

252-
mod serde {
254+
mod _serde {
253255
use super::{parse_or_cheap_failure, RoomName};
254256

255257
use std::fmt;

Diff for: src/data/rooms.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
//! Room result structures.
2+
use serde::{Deserialize, Serialize};
3+
24
use crate::{decoders::timespec_seconds, error};
35

46
/// A room state, returned by room status.

Diff for: src/data/users.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//! User-related shared data structures.
2+
use serde::{Deserialize, Serialize};
23

34
/// Badge type - what shape a badge should be.
45
#[derive(Serialize, Deserialize, Clone, Eq, PartialEq, Hash, Debug)]

Diff for: src/endpoints/leaderboard/find_rank.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
//! Interpreting the result of finding the rank of a specific user.
2+
use serde::{Deserialize, Serialize};
23

34
use crate::data;
45
use crate::error::{ApiError, Result};
56
use crate::EndpointResult;
67

78
/// Raw result for when the API endpoint is called with a specific season id.
8-
#[derive(serde_derive::Deserialize, Clone, Hash, Debug)]
9+
#[derive(serde::Deserialize, Clone, Hash, Debug)]
910
#[doc(hidden)]
1011
pub(crate) struct SingleResponse {
1112
// I have no idea what this is for, so not including in the documented and expected response.
@@ -18,14 +19,14 @@ pub(crate) struct SingleResponse {
1819
}
1920

2021
/// Raw result for when the API endpoint is called without a specific season id.
21-
#[derive(serde_derive::Deserialize, Clone, Hash, Debug)]
22+
#[derive(serde::Deserialize, Clone, Hash, Debug)]
2223
#[doc(hidden)]
2324
pub(crate) struct AllSeasonRanksResponse {
2425
ok: i32,
2526
list: Vec<InnerAllSeasonsResponse>,
2627
}
2728

28-
#[derive(serde_derive::Deserialize, Clone, Hash, Debug)]
29+
#[derive(serde::Deserialize, Clone, Hash, Debug)]
2930
struct InnerAllSeasonsResponse {
3031
// Again, no idea what this is for, so I'm not including it in the documented response.
3132
// _id: String,

Diff for: src/endpoints/leaderboard/page.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
//! Interpreting user leaderboard page results.
22
use std::collections::HashMap;
33

4+
use serde::{Deserialize, Serialize};
5+
46
use super::find_rank;
57
use crate::data;
68
use crate::error::{ApiError, Result};
79
use crate::EndpointResult;
810

911
/// Raw list results.
10-
#[derive(serde_derive::Deserialize, Clone, Debug)]
12+
#[derive(Deserialize, Clone, Debug)]
1113
#[doc(hidden)]
1214
pub(crate) struct Response {
1315
ok: i32,
@@ -16,7 +18,7 @@ pub(crate) struct Response {
1618
users: HashMap<String, ExtendedUserInfo>,
1719
}
1820

19-
#[derive(serde_derive::Deserialize, Clone, Hash, Debug)]
21+
#[derive(Deserialize, Clone, Hash, Debug)]
2022
struct ResponseRankedUser {
2123
//_id: String, // exists, but I don't know what it's for.
2224
rank: u32,
@@ -25,7 +27,7 @@ struct ResponseRankedUser {
2527
user: String,
2628
}
2729

28-
#[derive(serde_derive::Deserialize, Clone, Hash, Debug)]
30+
#[derive(Deserialize, Clone, Hash, Debug)]
2931
struct ExtendedUserInfo {
3032
_id: String,
3133
username: String,

Diff for: src/endpoints/leaderboard/season_list.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
//! Interpreting leaderboard season list results.
2+
use serde::{Deserialize, Serialize};
23

34
use crate::data;
45
use crate::error::{ApiError, Result};
56
use crate::EndpointResult;
67

78
/// Call raw result.
8-
#[derive(serde_derive::Deserialize, Clone, Hash, Debug)]
9+
#[derive(Deserialize, Clone, Hash, Debug)]
910
#[doc(hidden)]
1011
pub(crate) struct Response {
1112
ok: i32,
1213
seasons: Vec<Season>,
1314
}
1415

15-
#[derive(serde_derive::Deserialize, Clone, Hash, Debug)]
16+
#[derive(Deserialize, Clone, Hash, Debug)]
1617
struct Season {
1718
_id: String,
1819
name: String,

Diff for: src/endpoints/login.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//! Interpreting login responses.
22
use std::borrow::Cow;
33

4+
use serde::{Deserialize, Serialize};
5+
46
use crate::data;
57
use crate::error::{ApiError, Result};
68

@@ -30,7 +32,7 @@ impl<'a> LoginArgs<'a> {
3032
}
3133

3234
/// Login raw result.
33-
#[derive(serde_derive::Deserialize, Clone, Hash, Debug)]
35+
#[derive(Deserialize, Clone, Hash, Debug)]
3436
pub(crate) struct Response {
3537
ok: i32,
3638
token: Option<String>,

Diff for: src/endpoints/map_stats.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! Note: currently only supports "owner0" stats, not any other statistic that can also be retrieved with the same API.
44
use std::convert::AsRef;
55

6-
use serde::{Serialize, Serializer};
6+
use serde::{Deserialize, Serialize, Serializer};
77

88
use crate::data::{self, RoomName};
99
use crate::decoders::optional_timespec_seconds;
@@ -88,7 +88,7 @@ where
8888
}
8989

9090
/// Map stats raw result.
91-
#[derive(serde_derive::Deserialize, Clone, Hash, Debug)]
91+
#[derive(Deserialize, Clone, Hash, Debug)]
9292
#[doc(hidden)]
9393
pub(crate) struct Response {
9494
ok: i32,
@@ -98,7 +98,7 @@ pub(crate) struct Response {
9898
users: Vec<(String, UserResponse)>,
9999
}
100100

101-
#[derive(serde_derive::Deserialize, Clone, Hash, Debug)]
101+
#[derive(Deserialize, Clone, Hash, Debug)]
102102
#[serde(rename_all = "camelCase")]
103103
struct RoomResponse {
104104
status: String,
@@ -115,7 +115,7 @@ struct RoomResponse {
115115
hard_sign: Option<data::HardSign>,
116116
}
117117

118-
#[derive(serde_derive::Deserialize, Clone, Hash, Debug)]
118+
#[derive(Deserialize, Clone, Hash, Debug)]
119119
struct UserResponse {
120120
badge: data::Badge,
121121
_id: String,

Diff for: src/endpoints/memory_segment.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
//! Interpreting memory calls.
2+
use serde::Deserialize;
3+
24
use crate::{
35
data,
46
error::{ApiError, Result},
57
EndpointResult,
68
};
79

810
/// Call raw result.
9-
#[derive(serde_derive::Deserialize, Clone, Hash, Debug)]
11+
#[derive(Deserialize, Clone, Hash, Debug)]
1012
#[doc(hidden)]
1113
pub(crate) struct Response {
1214
ok: i32,

Diff for: src/endpoints/my_info.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Interpreting user self information.
22
use std::collections::HashMap;
33

4+
use serde::{Deserialize, Serialize};
45
use time::Timespec;
56

67
use crate::{
@@ -11,7 +12,7 @@ use crate::{
1112
};
1213

1314
/// User info raw result.
14-
#[derive(serde_derive::Deserialize, Clone, Debug)]
15+
#[derive(serde::Deserialize, Clone, Debug)]
1516
#[serde(rename_all = "camelCase")]
1617
pub(crate) struct Response {
1718
ok: i32,

Diff for: src/endpoints/recent_pvp.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//! Interpreting rooms in which PvP recently occurred. This is an "experimental" endpoint.
2+
use serde::Deserialize;
23

34
use crate::{
45
data,
@@ -33,20 +34,20 @@ impl RecentPvpArgs {
3334
}
3435

3536
/// Recent PvP raw result.
36-
#[derive(serde_derive::Deserialize, Clone, Hash, Debug)]
37+
#[derive(Deserialize, Clone, Hash, Debug)]
3738
pub(crate) struct Response {
3839
ok: i32,
3940
#[serde(with = "::tuple_vec_map")]
4041
pvp: Vec<(String, InnerShard)>,
4142
}
4243

43-
#[derive(serde_derive::Deserialize, Clone, Hash, Debug)]
44+
#[derive(Deserialize, Clone, Hash, Debug)]
4445
struct InnerShard {
4546
rooms: Vec<InnerRoom>,
4647
time: u32,
4748
}
4849

49-
#[derive(serde_derive::Deserialize, Clone, Hash, Debug)]
50+
#[derive(Deserialize, Clone, Hash, Debug)]
5051
struct InnerRoom {
5152
_id: String,
5253
#[serde(rename = "lastPvpTime")]

Diff for: src/endpoints/register.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//! Creating registration calls and interpreting registration results.
22
use std::borrow::Cow;
33

4+
use serde::{Deserialize, Serialize};
5+
46
use crate::{
57
data,
68
error::{ApiError, Result},
@@ -47,7 +49,7 @@ impl<'a> RegistrationArgs<'a> {
4749
}
4850

4951
/// Raw registration response.
50-
#[derive(serde_derive::Deserialize, Clone, Hash, Debug)]
52+
#[derive(Deserialize, Clone, Hash, Debug)]
5153
pub(crate) struct Response {
5254
ok: i32,
5355
}

Diff for: src/endpoints/room_overview.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//! Interpreting room overview results.
2+
use serde::{Deserialize, Serialize};
23

34
use crate::{
45
data::{self, Badge},
@@ -7,7 +8,7 @@ use crate::{
78
};
89

910
/// Room overview raw result.
10-
#[derive(serde_derive::Deserialize, Clone, Hash, Debug)]
11+
#[derive(serde::Deserialize, Clone, Hash, Debug)]
1112
#[serde(rename_all = "camelCase")]
1213
pub(crate) struct Response {
1314
ok: i32,
@@ -16,13 +17,13 @@ pub(crate) struct Response {
1617
stats_max: Option<RoomTotalStatsResponse>,
1718
}
1819

19-
#[derive(serde_derive::Deserialize, Clone, Hash, Debug)]
20+
#[derive(serde::Deserialize, Clone, Hash, Debug)]
2021
struct OwnerResponse {
2122
username: String,
2223
badge: Badge,
2324
}
2425

25-
#[derive(serde_derive::Deserialize, Clone, Hash, Debug)]
26+
#[derive(serde::Deserialize, Clone, Hash, Debug)]
2627
#[serde(rename_all = "camelCase")]
2728
struct RoomStatsResponse {
2829
energy_harvested: Vec<StatPointResponse>,
@@ -33,14 +34,14 @@ struct RoomStatsResponse {
3334
creeps_lost: Vec<StatPointResponse>,
3435
}
3536

36-
#[derive(serde_derive::Deserialize, Copy, Clone, Hash, Debug)]
37+
#[derive(serde::Deserialize, Copy, Clone, Hash, Debug)]
3738
#[serde(rename_all = "camelCase")]
3839
struct StatPointResponse {
3940
value: u32,
4041
end_time: u32,
4142
}
4243

43-
#[derive(serde_derive::Deserialize, Copy, Clone, Hash, Debug)]
44+
#[derive(serde::Deserialize, Copy, Clone, Hash, Debug)]
4445
#[serde(rename_all = "camelCase")]
4546
struct RoomTotalStatsResponse {
4647
energy_8: u32,

Diff for: src/endpoints/room_status.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//! Interpreting room status results.
2+
use serde::{Deserialize, Serialize};
23

34
use crate::{
45
data::{self, RoomName, RoomState},
@@ -8,13 +9,13 @@ use crate::{
89
};
910

1011
/// Room overview raw result.
11-
#[derive(serde_derive::Deserialize, Clone, Hash, Debug)]
12+
#[derive(serde::Deserialize, Clone, Hash, Debug)]
1213
pub(crate) struct Response {
1314
ok: i32,
1415
room: Option<InnerRoom>,
1516
}
1617

17-
#[derive(serde_derive::Deserialize, Clone, Hash, Debug)]
18+
#[derive(serde::Deserialize, Clone, Hash, Debug)]
1819
struct InnerRoom {
1920
/// The room's name
2021
_id: String,

Diff for: src/endpoints/room_terrain.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Interpreting room terrain results.
2-
32
use arrayvec::ArrayVec;
3+
use serde::{Deserialize, Serialize};
44

55
use crate::{
66
data,
@@ -9,13 +9,13 @@ use crate::{
99
};
1010

1111
/// Room overview raw result.
12-
#[derive(serde_derive::Deserialize, Clone, Hash, Debug)]
12+
#[derive(serde::Deserialize, Clone, Hash, Debug)]
1313
pub(crate) struct Response {
1414
ok: i32,
1515
terrain: Option<Vec<InnerResponse>>,
1616
}
1717

18-
#[derive(serde_derive::Deserialize, Clone, Hash, Debug)]
18+
#[derive(serde::Deserialize, Clone, Hash, Debug)]
1919
struct InnerResponse {
2020
// this is returned as part of the data, but what the heck is it even for?
2121
/// A cache key maybe?

Diff for: src/endpoints/set_memory_segment.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
//! Interpreting memory calls.
22
use std::borrow::Cow;
33

4+
use serde::Serialize;
5+
46
use crate::{
57
data,
68
error::{ApiError, Result},
79
EndpointResult,
810
};
911

1012
/// Call raw result.
11-
#[derive(serde_derive::Deserialize, Clone, Hash, Debug)]
13+
#[derive(serde::Deserialize, Clone, Hash, Debug)]
1214
#[doc(hidden)]
1315
pub(crate) struct Response {
1416
ok: i32,

0 commit comments

Comments
 (0)