From ae52f1113f29eb99505df5a402701e79df7d8fe9 Mon Sep 17 00:00:00 2001 From: Hector van der Aa Date: Fri, 5 Dec 2025 19:53:03 +0100 Subject: [PATCH] Clippy cleanup --- src/config/stream.rs | 11 ++++------- src/instance.rs | 13 +++++-------- src/utils.rs | 4 +--- 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/src/config/stream.rs b/src/config/stream.rs index 5ebd259..d691ec8 100644 --- a/src/config/stream.rs +++ b/src/config/stream.rs @@ -180,9 +180,7 @@ impl StreamLine { let input = self.line.as_str(); let re = Regex::new(r"\[(.*?)\]").unwrap(); let time_s = re.captures(input).map(|v| v[1].to_string()); - if time_s.is_none() { - return None; - } + time_s.as_ref()?; let time = NaiveTime::parse_from_str(&time_s.unwrap(), "%H:%M:%S").ok()?; let today = Local::now().date_naive(); @@ -233,19 +231,18 @@ impl Display for InstanceEvent { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let head = format!( "UUID: {}\nTimestamp:{}\nPayload:\n", - self.id.to_string(), - self.timestamp.to_string() + self.id, self.timestamp ); match self.payload.clone() { EventPayload::StdLine { line } => { let full = format!("{}{}", head, line); - write!(f, "{}\n", full) + writeln!(f, "{}", full) } #[cfg(feature = "events")] EventPayload::StateChange { old, new } => { let full = format!("{}State changed: {:?} -> {:?}", head, old, new); - write!(f, "{}\n", full) + writeln!(f, "{}", full) } } } diff --git a/src/instance.rs b/src/instance.rs index 71e56ea..1ec6017 100644 --- a/src/instance.rs +++ b/src/instance.rs @@ -14,7 +14,7 @@ use uuid::Uuid; #[cfg(feature = "events")] use crate::config::stream::InstanceEvent; use crate::{ - config::{MinecraftType, MinecraftVersion, StreamLine, StreamSource, stream::EventPayload}, + config::{MinecraftType, MinecraftVersion, StreamSource, stream::EventPayload}, error::{HandleError, ServerError, SubscribeError}, }; @@ -319,11 +319,8 @@ impl InstanceHandle { } maybe_event = internal_rx.recv() => { - match maybe_event { - Some(event) => { - println!("event: {}", event); - } - _ => (), + if let Some(event) = maybe_event { + println!("event: {}", event); } } } @@ -362,7 +359,7 @@ impl InstanceHandle { child.kill().await.map_err(|_| ServerError::CommandFailed)?; self.transition_status(InstanceStatus::Killed).await; - sleep(Duration::from_secs(1)); + sleep(Duration::from_secs(1)).await; self.shutdown.cancel(); self.child = None; Ok(()) @@ -380,7 +377,7 @@ impl InstanceHandle { child.wait().await.map_err(|_| ServerError::CommandFailed)?; self.transition_status(InstanceStatus::Stopped).await; - sleep(Duration::from_secs(1)); + sleep(Duration::from_secs(1)).await; self.shutdown.cancel(); self.child = None; Ok(()) diff --git a/src/utils.rs b/src/utils.rs index 6f686c3..1ba477b 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -4,9 +4,7 @@ use regex::Regex; pub fn extract_timestamp(input: &str) -> Option> { let re = Regex::new(r"\[(.*?)\]").unwrap(); let time_s = re.captures(input).map(|v| v[1].to_string()); - if time_s.is_none() { - return None; - } + time_s.as_ref()?; let time = NaiveTime::parse_from_str(&time_s.unwrap(), "%H:%M:%S").ok()?; let today = Local::now().date_naive();