From 3ba9250cca73b3e692d9a014f37595d388ef88f9 Mon Sep 17 00:00:00 2001 From: Xevion Date: Thu, 11 Dec 2025 12:01:26 -0600 Subject: [PATCH] refactor: apply clippy suggestions --- src/main.rs | 7 ++----- src/models.rs | 24 ++++++++++++------------ src/railway.rs | 4 ++-- src/utility.rs | 2 +- 4 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/main.rs b/src/main.rs index 5c8ca7c..0743530 100644 --- a/src/main.rs +++ b/src/main.rs @@ -320,7 +320,7 @@ pub async fn notify(req: &mut Request, res: &mut Response) { let target_session = store .sessions .iter_mut() - .find(|(_, session)| session.downloads.iter().find(|d| d.token == key).is_some()); + .find(|(_, session)| session.downloads.iter().any(|d| d.token == key)); match target_session { Some((_, session)) => { @@ -373,10 +373,7 @@ fn get_session_id(req: &Request, depot: &Depot) -> Option { // Otherwise, just use whatever the Cookie might have match req.cookie("Session") { - Some(cookie) => match cookie.value().parse::() { - Ok(id) => Some(id), - _ => None, - }, + Some(cookie) => cookie.value().parse::().ok(), None => { tracing::warn!("Session was not provided in cookie or depot"); None diff --git a/src/models.rs b/src/models.rs index 2064eaf..df46058 100644 --- a/src/models.rs +++ b/src/models.rs @@ -47,7 +47,7 @@ impl Session { "{}-{:08x}{}{}", exe.name, token, - if exe.extension.len() > 0 { "." } else { "" }, + if !exe.extension.is_empty() { "." } else { "" }, exe.extension ), last_used: chrono::Utc::now(), @@ -55,7 +55,7 @@ impl Session { }; self.downloads.push(download); - return self.downloads.last().unwrap(); + self.downloads.last().unwrap() } // Delete a download from the session @@ -81,8 +81,8 @@ impl Session { let result = tx.send(Ok(Message::text(serde_json::to_string(&message).unwrap()))); match result { - Ok(_) => return Ok(()), - Err(e) => return Err(anyhow::anyhow!("Error sending message: {}", e)), + Ok(_) => Ok(()), + Err(e) => Err(anyhow::anyhow!("Error sending message: {}", e)), } } @@ -124,7 +124,7 @@ impl State { } pub fn add_executable(&mut self, exe_type: &str, exe_path: &str) { - let data = std::fs::read(&exe_path).expect("Unable to read file"); + let data = std::fs::read(exe_path).expect("Unable to read file"); let pattern = "a".repeat(1024); let key_start = search(&data, pattern.as_bytes(), 0).unwrap(); @@ -142,8 +142,8 @@ impl State { filename: path.file_name().unwrap().to_str().unwrap().to_string(), name: name.to_string(), extension: extension.to_string(), - key_start: key_start, - key_end: key_end, + key_start, + key_end, }; self.executables.insert(exe_type.to_string(), exe); @@ -183,7 +183,7 @@ impl State { .build(), ); - return id; + id } pub fn executable_json(&self) -> Vec { @@ -197,7 +197,7 @@ impl State { }); } - return executables; + executables } } @@ -222,12 +222,12 @@ impl Executable { // If the new key is shorter than the old key, we just write over the remaining data if new_key.len() < self.key_end - self.key_start { - for i in self.key_start + new_key.len()..self.key_end { - data[i] = b' '; + for item in data.iter_mut().take(self.key_end).skip(self.key_start + new_key.len()) { + *item = b' '; } } - return data; + data } } diff --git a/src/railway.rs b/src/railway.rs index ade2eba..96ee35e 100644 --- a/src/railway.rs +++ b/src/railway.rs @@ -203,6 +203,8 @@ pub async fn fetch_build_logs() -> Result { serde_json::from_value::>(build_logs_value.clone()) { let mut filtered_logs = Vec::new(); + let starting_container_pattern = + regex::Regex::new(r"(?i)Starting\s+Container").unwrap(); for entry in build_logs { // Check if we should stop at this message @@ -210,8 +212,6 @@ pub async fn fetch_build_logs() -> Result { // For "Build time" messages, include them // For "Starting Container" messages, stop before them let clean_message = strip_ansi_codes(&entry.message); - let starting_container_pattern = - regex::Regex::new(r"(?i)Starting\s+Container").unwrap(); if starting_container_pattern.is_match(&clean_message) { // Stop before "Starting Container" message diff --git a/src/utility.rs b/src/utility.rs index 4f294af..cf06f23 100644 --- a/src/utility.rs +++ b/src/utility.rs @@ -7,7 +7,7 @@ pub(crate) fn search(buf: &[u8], pattern: &[u8], start_index: usize) -> Option