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

Commit 16543d0

Browse files
committed
Sort derives canonically
rust-lang/style-team#154
1 parent 2645390 commit 16543d0

File tree

5 files changed

+28
-15
lines changed

5 files changed

+28
-15
lines changed

src/api.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub type GetGameDetailsResponse = Game;
1515

1616
const MOCK_API: bool = false;
1717

18-
#[derive(Serialize, Deserialize, Debug)]
18+
#[derive(Debug, Serialize, Deserialize)]
1919
#[serde(deny_unknown_fields)]
2020
pub struct ApplicationVersion {
2121
pub game_version: String,
@@ -25,14 +25,14 @@ pub struct ApplicationVersion {
2525
pub platform: String,
2626
}
2727

28-
#[derive(Serialize, Deserialize, Debug)]
28+
#[derive(Debug, Serialize, Deserialize)]
2929
pub struct Mod {
3030
pub name: String,
3131
pub version: String,
3232
}
3333

3434
// более правильным было бы назвать этот класс GameSnapshot
35-
#[derive(Serialize, Deserialize, Debug)]
35+
#[derive(Debug, Serialize, Deserialize)]
3636
#[serde(deny_unknown_fields)]
3737
pub struct Game {
3838
// common fields

src/fetcher_get_game_details.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::api;
1212
use crate::global_config::GLOBAL_CONFIG;
1313
use crate::state::{GameId, Mod, StateLock};
1414

15-
#[derive(Serialize, Deserialize, Eq, PartialEq)]
15+
#[derive(Eq, PartialEq, Serialize, Deserialize)]
1616
pub struct State {
1717
pub game_ids: VecDeque<GameId>,
1818
}

src/state/big_string.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use hashbrown::HashMap;
44
use serde::{Deserialize, Serialize};
55

66
// todo documentation
7-
#[derive(Serialize, Deserialize, Eq, PartialEq)]
7+
#[derive(Eq, PartialEq, Serialize, Deserialize)]
88
pub struct BigString {
99
#[serde(skip)]
1010
debug_name: String,
@@ -104,7 +104,7 @@ impl BigString {
104104
}
105105

106106
// индекс подстроки в большой строке
107-
#[derive(Copy, Clone, Serialize, Deserialize, Eq, PartialEq, Hash)]
107+
#[derive(Copy, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)]
108108
pub struct BigStringPart(NonZeroU32);
109109

110110
// type-safe часть (sub-slice) BigString

src/state/mod.rs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::fmt;
12
use std::num::NonZeroU32;
23
use std::sync::Arc;
34
use std::time::{SystemTime, UNIX_EPOCH};
@@ -14,9 +15,15 @@ mod big_string;
1415

1516
/// unix time, с точностью до минут
1617
/// (число минут, прошедшее с UNIX_EPOCH)
17-
#[derive(Copy, Clone, Debug, Serialize, Deserialize, Ord, PartialOrd, Eq, PartialEq)]
18+
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize)]
1819
pub struct TimeMinutes(pub NonZeroU32);
1920

21+
impl fmt::Debug for TimeMinutes {
22+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
23+
write!(f, "{}", self.0)
24+
}
25+
}
26+
2027
impl TimeMinutes {
2128
pub const WEEK: u32 = 7 * 24 * 60;
2229

@@ -44,17 +51,23 @@ pub type HostId = [u8; 32];
4451
/// будем использовать собственную нумерацию серверов, обозначаемую ServerId
4552
/// ServerId — индекс для массива game.game_ids
4653
/// `game_ids[ServerId]` — последний game_id этого сервера (такой что .next_game_id == None)
47-
#[derive(Debug, Copy, Clone, Serialize, Deserialize, Eq, PartialEq, Hash)]
54+
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug, Serialize, Deserialize)]
4855
pub struct ServerId(NonZeroU32);
4956

50-
#[derive(Clone, Serialize, Deserialize, Eq, PartialEq, Hash)]
57+
impl fmt::Display for ServerId {
58+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
59+
write!(f, "{}", self.0.get())
60+
}
61+
}
62+
63+
#[derive(Clone, Eq, PartialEq, Hash, Serialize, Deserialize)]
5164
#[serde(rename_all = "camelCase")]
5265
pub struct Mod {
5366
pub name: BigStringPart,
5467
pub version: BigStringPart,
5568
}
5669

57-
#[derive(Clone, Serialize, Deserialize, Eq, PartialEq)]
70+
#[derive(Clone, Eq, PartialEq, Serialize, Deserialize)]
5871
#[serde(rename_all = "camelCase")]
5972
pub struct PlayerInterval {
6073
pub player_index: BigStringPart,
@@ -77,7 +90,7 @@ impl PlayerInterval {
7790
// в течении сессии метаинформация о сервере (название, версия, моды и т.д.) не должны меняться
7891
// ожидается, что сессия длится непрерывный отрезок по времени
7992
// (однако по наблюдениям сессия может прерываться на очень большой промежуток времени, вплоть до ~30 часов)
80-
#[derive(Clone, Serialize, Deserialize, Eq, PartialEq)]
93+
#[derive(Clone, Eq, PartialEq, Serialize, Deserialize)]
8194
#[serde(rename_all = "camelCase")]
8295
pub struct Game {
8396
pub game_id: GameId,
@@ -126,7 +139,7 @@ impl Game {
126139
}
127140

128141
pub fn maximum_number_players(&self) -> (usize, TimeMinutes) {
129-
#[derive(Ord, PartialOrd, Eq, PartialEq)]
142+
#[derive(Eq, PartialEq, Ord, PartialOrd)]
130143
enum EventType { Begin, End }
131144

132145
let now = TimeMinutes::now();
@@ -207,7 +220,7 @@ pub type StateLock = Arc<RwLock<State>>;
207220
// pub type GamesMap = std::collections::BTreeMap<GameId, Game>;
208221
pub type GamesMap = crate::util::games_map::GamesMap;
209222

210-
#[derive(Serialize, Deserialize, Eq, PartialEq)]
223+
#[derive(Eq, PartialEq, Serialize, Deserialize)]
211224
#[serde(rename_all = "camelCase")]
212225
pub struct State {
213226
pub games: GamesMap,

src/state/updater.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use crate::state::{Game, GameId, HostId, PlayerInterval, State, StateLock, TimeM
3131
// }
3232
//}
3333

34-
#[derive(Serialize, Deserialize, Eq, PartialEq)]
34+
#[derive(Eq, PartialEq, Serialize, Deserialize)]
3535
pub struct UpdaterState {
3636
pub scheduled_to_merge_host_ids: HashMap<HostId, HostIdMergeInfo>,
3737
}
@@ -124,7 +124,7 @@ fn update_game(game_snapshot: &api::Game, state: &mut State, time: TimeMinutes)
124124
}
125125
}
126126

127-
#[derive(Serialize, Deserialize, Eq, PartialEq)]
127+
#[derive(Eq, PartialEq, Serialize, Deserialize)]
128128
pub struct HostIdMergeInfo {
129129
// время первого события появлении/исчезновении game_id
130130
pub time_begin: TimeMinutes,

0 commit comments

Comments
 (0)