From 16451467be9369f1528aae5a2103e6fb1bbf9863 Mon Sep 17 00:00:00 2001 From: Philipp Erhardt Date: Tue, 26 Dec 2023 11:33:47 +0100 Subject: [PATCH] Formatting --- client/src/main.rs | 22 +++++++++++----------- server/src/config.rs | 25 ++++++++++++++----------- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/client/src/main.rs b/client/src/main.rs index 09adff7..e142983 100644 --- a/client/src/main.rs +++ b/client/src/main.rs @@ -111,19 +111,19 @@ impl MystiClient { let socket = { let mut fail_count = 0; loop { + match connect_async(moved_server_url.clone()).await { + Ok((socket, _)) => break socket, + Err(e) => { + if fail_count % 12 == 0 { + eprintln!("Failed to connect to server: {}", e); + } + fail_count += 1; - match connect_async(moved_server_url.clone()).await { - Ok((socket, _)) => break socket, - Err(e) => { - if fail_count % 12 == 0 { - eprintln!("Failed to connect to server: {}", e); + tokio::time::sleep(Duration::from_secs(5)).await; } - fail_count += 1; - - tokio::time::sleep(Duration::from_secs(5)).await; - } - }; - }}; + }; + } + }; println!("Connected to server"); diff --git a/server/src/config.rs b/server/src/config.rs index 596fa3c..8a053c9 100644 --- a/server/src/config.rs +++ b/server/src/config.rs @@ -1,4 +1,4 @@ -use std::{net::IpAddr, str::FromStr, path::Display}; +use std::{net::IpAddr, str::FromStr}; use anyhow::{Context, Result}; use macaddr::MacAddr6; @@ -11,7 +11,6 @@ pub struct Config { pub token: String, } - #[derive(Deserialize, Debug, Clone)] pub struct WakeOnLanConfig { pub target_addr: ParseableMacAddr, @@ -48,12 +47,11 @@ impl<'de> serde::Deserialize<'de> for ParseableMacAddr { use serde::de::Error; let mac = String::deserialize(deserializer).and_then(|s| { - MacAddr6::from_str(&s).map_err(|e| match e { + MacAddr6::from_str(&s).map_err(|e| match e { ParseError::InvalidLength(_) => Error::invalid_length(s.len(), &"17"), - ParseError::InvalidCharacter(c, _) => Error::invalid_value( - serde::de::Unexpected::Char(c), - &"a valid hex character" - ), + ParseError::InvalidCharacter(c, _) => { + Error::invalid_value(serde::de::Unexpected::Char(c), &"a valid hex character") + } }) })?; @@ -61,7 +59,6 @@ impl<'de> serde::Deserialize<'de> for ParseableMacAddr { } } - #[cfg(test)] mod tests { use super::*; @@ -71,8 +68,14 @@ mod tests { assert_eq!(config.web_port, 9138); assert_eq!(config.token, "some_token"); - assert_eq!(config.wake_on_lan.target_addr.0, MacAddr6::new(0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA)); - assert_eq!(config.wake_on_lan.router_addr.unwrap(), IpAddr::from_str("255.255.255.255").unwrap()); + assert_eq!( + config.wake_on_lan.target_addr.0, + MacAddr6::new(0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA) + ); + assert_eq!( + config.wake_on_lan.router_addr.unwrap(), + IpAddr::from_str("255.255.255.255").unwrap() + ); } #[test] @@ -98,6 +101,6 @@ mod tests { target_addr = "AA:AA:AA:aa:AA:AA" router_addr = "255.255.255.255""#; - assert_config(config_str); + assert_config(config_str); } }