find excuses to use shiny new 🦀 features
authoralfadur
Sat, 19 Jun 2021 17:48:10 +0300
changeset 15795 40929af15167
parent 15794 7598960819a1
child 15796 2939d8599418
find excuses to use shiny new 🦀 features
rust/hedgewars-server/Cargo.toml
rust/hedgewars-server/src/handlers/common.rs
rust/hedgewars-server/src/handlers/inroom.rs
rust/hedgewars-server/src/main.rs
rust/hedgewars-server/src/protocol.rs
rust/hedgewars-server/src/protocol/messages.rs
rust/hedgewars-server/src/server/database.rs
--- a/rust/hedgewars-server/Cargo.toml	Thu Jun 17 19:32:26 2021 +0200
+++ b/rust/hedgewars-server/Cargo.toml	Sat Jun 19 17:48:10 2021 +0300
@@ -10,18 +10,18 @@
 default = []
 
 [dependencies]
-getopts = "0.2.18"
-rand = "0.6"
+getopts = "0.2"
+rand = "0.7"
 chrono = "0.4"
 mio = "0.6"
-mio-extras = "2.0.5"
+mio-extras = "2.0"
 slab = "0.4"
 netbuf = "0.4"
 nom = "5.1"
-env_logger = "0.6"
+env_logger = "0.8"
 log = "0.4"
-base64 = "0.10"
-bitflags = "1.0"
+base64 = "0.13"
+bitflags = "1.1"
 serde = "1.0"
 serde_yaml = "0.8"
 serde_derive = "1.0"
--- a/rust/hedgewars-server/src/handlers/common.rs	Thu Jun 17 19:32:26 2021 +0200
+++ b/rust/hedgewars-server/src/handlers/common.rs	Sat Jun 19 17:48:10 2021 +0300
@@ -494,7 +494,7 @@
         Ok(VoteResult::Submitted) => {
             response.add(server_chat("Your vote has been counted.".to_string()).send_self())
         }
-        Ok(VoteResult::Succeeded(_)) | Ok(VoteResult::Failed) => response.add(
+        Ok(VoteResult::Succeeded(_) | VoteResult::Failed) => response.add(
             server_chat("Voting closed.".to_string())
                 .send_all()
                 .in_room(room_id),
--- a/rust/hedgewars-server/src/handlers/inroom.rs	Thu Jun 17 19:32:26 2021 +0200
+++ b/rust/hedgewars-server/src/handlers/inroom.rs	Sat Jun 19 17:48:10 2021 +0300
@@ -448,7 +448,7 @@
         Rnd(v) => {
             let result = rnd_reply(&v);
             let mut echo = vec!["/rnd".to_string()];
-            echo.extend(v.into_iter());
+            echo.extend(v);
             let chat_msg = ChatMsg {
                 nick: client.nick.clone(),
                 msg: echo.join(" "),
--- a/rust/hedgewars-server/src/main.rs	Thu Jun 17 19:32:26 2021 +0200
+++ b/rust/hedgewars-server/src/main.rs	Sat Jun 19 17:48:10 2021 +0300
@@ -71,7 +71,7 @@
         for event in events.iter() {
             if event.readiness() & Ready::readable() == Ready::readable() {
                 match event.token() {
-                    token @ utils::SERVER_TOKEN | token @ utils::SECURE_SERVER_TOKEN => {
+                    token @ (utils::SERVER_TOKEN | utils::SECURE_SERVER_TOKEN) => {
                         match hw_network.accept_client(&poll, token) {
                             Ok(()) => (),
                             Err(e) => debug!("Error accepting client: {}", e),
--- a/rust/hedgewars-server/src/protocol.rs	Thu Jun 17 19:32:26 2021 +0200
+++ b/rust/hedgewars-server/src/protocol.rs	Sat Jun 19 17:48:10 2021 +0300
@@ -55,7 +55,7 @@
                         self.buf.consume(self.buf.len() - length);
                     }
                     Err(nom::Err::Incomplete(_)) => break,
-                    Err(nom::Err::Failure(e)) | Err(nom::Err::Error(e)) => {
+                    Err(nom::Err::Failure(e) | nom::Err::Error(e)) => {
                         debug!("Invalid message: {:?}", e);
                         if !self.recover() || self.buf.is_empty() {
                             break;
--- a/rust/hedgewars-server/src/protocol/messages.rs	Thu Jun 17 19:32:26 2021 +0200
+++ b/rust/hedgewars-server/src/protocol/messages.rs	Sat Jun 19 17:48:10 2021 +0300
@@ -213,7 +213,7 @@
             Scheme(n, s) if s.is_empty() => ("SCHEME".to_string(), vec![n.to_string()]),
             Scheme(n, s) => ("SCHEME".to_string(), {
                 let mut v = vec![n.to_string()];
-                v.extend(s.clone().into_iter());
+                v.extend(s.clone());
                 v
             }),
             Script(s) => ("SCRIPT".to_string(), vec![s.to_string()]),
@@ -261,12 +261,6 @@
     };
 }
 
-#[cfg(test)]
-macro_rules! several {
-    [$part: expr] => { once($part) };
-    [$part: expr, $($other: expr),*] => { once($part).chain(several![$($other),*]) };
-}
-
 impl HwProtocolMessage {
     /** Converts the message to a raw `String`, which can be sent over the network.
      *
@@ -330,7 +324,7 @@
                 info.difficulty,
                 info.hedgehogs
                     .iter()
-                    .flat_map(|h| several![&h.name[..], &h.hat[..]])
+                    .flat_map(|h| [&h.name[..], &h.hat[..]])
                     .collect::<Vec<_>>()
                     .join("\n")
             ],
--- a/rust/hedgewars-server/src/server/database.rs	Thu Jun 17 19:32:26 2021 +0200
+++ b/rust/hedgewars-server/src/server/database.rs	Sat Jun 19 17:48:10 2021 +0300
@@ -105,7 +105,7 @@
 
     pub fn store_stats(&mut self, stats: &ServerStatistics) -> Result<(), Error> {
         if let Some(pool) = &self.pool {
-            for mut stmt in pool.prepare(STORE_STATS_QUERY).into_iter() {
+            for mut stmt in pool.prepare(STORE_STATS_QUERY) {
                 stmt.execute(params! {
                     "players" => stats.players,
                     "rooms" => stats.rooms,