Adopt more recent versions of dependencies, apply clippy fixes
authorunC0Rr
Mon, 02 Oct 2023 21:36:13 +0200
changeset 15979 1635ce22b214
parent 15978 20adaa127663
child 15980 39ae4ed7de6e
Adopt more recent versions of dependencies, apply clippy fixes
rust/hedgewars-checker/Cargo.toml
rust/hedgewars-checker/src/main.rs
--- a/rust/hedgewars-checker/Cargo.toml	Thu Aug 24 20:15:40 2023 +0200
+++ b/rust/hedgewars-checker/Cargo.toml	Mon Oct 02 21:36:13 2023 +0200
@@ -5,14 +5,14 @@
 edition = "2018"
 
 [dependencies]
-rust-ini = "0.18"
-dirs = "4"
+rust-ini = "0.19"
+dirs = "5.0"
 argparse = "0.2"
 log = "0.4"
 stderrlog = "0.5"
 netbuf = "0.4"
 tempfile = "3.0"
-base64 = "0.13"
+base64 = "0.21"
 hedgewars-network-protocol = { path = "../hedgewars-network-protocol" }
 anyhow = "1.0"
 tokio = {version="1", features = ["full"]}
--- a/rust/hedgewars-checker/src/main.rs	Thu Aug 24 20:15:40 2023 +0200
+++ b/rust/hedgewars-checker/src/main.rs	Mon Oct 02 21:36:13 2023 +0200
@@ -1,5 +1,6 @@
 use anyhow::{bail, Result};
 use argparse::{ArgumentParser, Store};
+use base64::{engine::general_purpose, Engine};
 use hedgewars_network_protocol::{
     messages::HwProtocolMessage as ClientMessage, messages::HwServerMessage::*, parser,
 };
@@ -12,8 +13,8 @@
 async fn check(executable: &str, data_prefix: &str, buffer: &[String]) -> Result<Vec<String>> {
     let mut replay = tempfile::NamedTempFile::new()?;
 
-    for line in buffer.into_iter() {
-        replay.write(&base64::decode(line)?)?;
+    for line in buffer.iter() {
+        replay.write_all(&general_purpose::STANDARD.decode(line)?)?;
     }
 
     let temp_file_path = replay.path();
@@ -43,7 +44,7 @@
 
     let mut engine_lines = output
         .stderr
-        .split(|b| *b == '\n' as u8)
+        .split(|b| *b == b'\n')
         .skip_while(|l| *l != b"WINNERS" && *l != b"DRAW");
 
     // debug!("Engine lines: {:?}", &engine_lines);
@@ -83,7 +84,7 @@
 
     // println!("Engine lines: {:?}", &result);
 
-    if result.len() > 0 {
+    if !result.is_empty() {
         Ok(result)
     } else {
         bail!("no data from engine")
@@ -133,27 +134,27 @@
                     debug!("Check result: [{:?}]", result);
 
                     stream
-                        .write(
+                        .write_all(
                             ClientMessage::CheckedOk(result)
                                 .to_raw_protocol()
                                 .as_bytes(),
                         )
                         .await?;
                     stream
-                        .write(ClientMessage::CheckerReady.to_raw_protocol().as_bytes())
+                        .write_all(ClientMessage::CheckerReady.to_raw_protocol().as_bytes())
                         .await?;
                 }
                 Err(e) => {
                     info!("Check failed: {:?}", e);
                     stream
-                        .write(
+                        .write_all(
                             ClientMessage::CheckedFail("error".to_owned())
                                 .to_raw_protocol()
                                 .as_bytes(),
                         )
                         .await?;
                     stream
-                        .write(ClientMessage::CheckerReady.to_raw_protocol().as_bytes())
+                        .write_all(ClientMessage::CheckerReady.to_raw_protocol().as_bytes())
                         .await?;
                 }
             }
@@ -183,7 +184,7 @@
                 Connected(_, _) => {
                     info!("Connected");
                     stream
-                        .write(
+                        .write_all(
                             ClientMessage::Checker(
                                 protocol_number,
                                 username.to_owned(),
@@ -196,12 +197,12 @@
                 }
                 Ping => {
                     stream
-                        .write(ClientMessage::Pong.to_raw_protocol().as_bytes())
+                        .write_all(ClientMessage::Pong.to_raw_protocol().as_bytes())
                         .await?;
                 }
                 LogonPassed => {
                     stream
-                        .write(ClientMessage::CheckerReady.to_raw_protocol().as_bytes())
+                        .write_all(ClientMessage::CheckerReady.to_raw_protocol().as_bytes())
                         .await?;
                 }
                 Replay(lines) => {
@@ -216,12 +217,12 @@
                     info!("Chat [{}]: {}", nick, msg);
                 }
                 RoomAdd(fields) => {
-                    let l = fields.into_iter();
-                    info!("Room added: {}", l.skip(1).next().unwrap());
+                    let mut l = fields.into_iter();
+                    info!("Room added: {}", l.nth(1).unwrap());
                 }
                 RoomUpdated(name, fields) => {
-                    let l = fields.into_iter();
-                    let new_name = l.skip(1).next().unwrap();
+                    let mut l = fields.into_iter();
+                    let new_name = l.nth(1).unwrap();
 
                     if name != new_name {
                         info!("Room renamed: {}", new_name);
@@ -245,7 +246,7 @@
 async fn get_protocol_number(executable: &str) -> Result<u16> {
     let output = Command::new(executable).arg("--protocol").output().await?;
 
-    Ok(u16::from_str(&String::from_utf8(output.stdout).unwrap().trim()).unwrap_or(55))
+    Ok(u16::from_str(String::from_utf8(output.stdout).unwrap().trim()).unwrap_or(55))
 }
 
 #[tokio::main]
@@ -279,7 +280,7 @@
     info!("Executable: {}", exe);
     info!("Data dir: {}", prefix);
 
-    let protocol_number = get_protocol_number(&exe.as_str()).await.unwrap_or_default();
+    let protocol_number = get_protocol_number(exe.as_str()).await.unwrap_or_default();
 
     info!("Using protocol number {}", protocol_number);
 
@@ -288,8 +289,8 @@
 
     let (network_result, checker_result) = tokio::join!(
         connect_and_run(
-            &username,
-            &password,
+            username,
+            password,
             protocol_number,
             replay_sender,
             results_receiver