diff --git a/torrential/build.rs b/torrential/build.rs index 23828b9f..2481ed17 100644 --- a/torrential/build.rs +++ b/torrential/build.rs @@ -2,18 +2,17 @@ use std::fs::{self, read_dir}; use protobuf_codegen::Codegen; -const OUT_DIR: &'static str = "./src/proto/"; +const OUT_DIR: &str = "./src/proto/"; fn main() { let files = read_dir("./proto").unwrap(); let files = files.map(|v| format!("proto/{}", v.unwrap().file_name().into_string().unwrap())); - read_dir(OUT_DIR).unwrap().into_iter().for_each(|v| { - if let Ok(entry) = v { - if entry.file_name().to_str().unwrap().ends_with(".rs") { + read_dir(OUT_DIR).unwrap().for_each(|v| { + if let Ok(entry) = v + && entry.file_name().to_str().unwrap().ends_with(".rs") { fs::remove_file(entry.path()).unwrap(); } - } }); Codegen::new() diff --git a/torrential/src/downloads/download.rs b/torrential/src/downloads/download.rs index 91134f68..d8cd4551 100644 --- a/torrential/src/downloads/download.rs +++ b/torrential/src/downloads/download.rs @@ -22,11 +22,12 @@ pub struct DownloadContext { last_access: Instant, } impl DownloadContext { + #[must_use] pub fn last_access(&self) -> Instant { self.last_access } pub fn reset_last_access(&mut self) { - self.last_access = Instant::now() + self.last_access = Instant::now(); } } @@ -71,7 +72,7 @@ fn create_backend( create_backend_constructor(&version_path).ok_or(StatusCode::INTERNAL_SERVER_ERROR)?; let backend = backend() - .inspect_err(|err| warn!("failed to create version backend: {:?}", err)) + .inspect_err(|err| warn!("failed to create version backend: {err:?}")) .map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?; Ok(backend) } diff --git a/torrential/src/downloads/handlers.rs b/torrential/src/downloads/handlers.rs index ad597bf1..f94064de 100644 --- a/torrential/src/downloads/handlers.rs +++ b/torrential/src/downloads/handlers.rs @@ -67,9 +67,9 @@ impl AsyncRead for SpeedtestStream { match amount { Ok(amount) => self.remaining -= amount, Err(err) => return Poll::Ready(Err(err)), - }; - }; - return Poll::Ready(Ok(())); + } + } + Poll::Ready(Ok(())) } } diff --git a/torrential/src/downloads/serve.rs b/torrential/src/downloads/serve.rs index d700a75f..5847826c 100644 --- a/torrential/src/downloads/serve.rs +++ b/torrential/src/downloads/serve.rs @@ -49,7 +49,7 @@ impl<'a, T: Stream> SemaphoreStream<'a, T> { } } -impl<'a, T: Stream> Stream for SemaphoreStream<'a, T> +impl Stream for SemaphoreStream<'_, T> where T: Stream, { @@ -160,7 +160,7 @@ async fn get_file_reader( ) .await .map_err(|v| { - error!("reader error for '{}': {v:?}", relative_filename); + error!("reader error for '{relative_filename}': {v:?}"); StatusCode::INTERNAL_SERVER_ERROR }) } @@ -181,13 +181,13 @@ async fn get_or_create_context<'a>( if let Some(already_done) = context_cache.get_mut(&key) { Ok(already_done) } else { - info!("generating context for {}...", game_id); + info!("generating context for {game_id}..."); let context_result = create_download_context(state, game_id.clone(), version_name.clone()).await?; state.context_cache.insert(key.clone(), context_result); - info!("continuing download for {}", game_id); + info!("continuing download for {game_id}"); drop(permit); diff --git a/torrential/src/droplet/backend.rs b/torrential/src/droplet/backend.rs index d91ba401..5cda2ce2 100644 --- a/torrential/src/droplet/backend.rs +++ b/torrential/src/droplet/backend.rs @@ -1,10 +1,9 @@ use std::{ path::Path, - sync::{Arc, LazyLock}, + sync::Arc, }; use anyhow::anyhow; -use dashmap::DashMap; use droplet_rs::versions::types::VersionBackend; use protobuf::Message; @@ -48,7 +47,7 @@ pub async fn has_backend_rpc( fn create_backend(path: &String) -> Result, anyhow::Error> { let backend_constructor = droplet_rs::versions::create_backend_constructor(Path::new(path)) - .ok_or(anyhow!("backend doesn't exist at path {}", path))?; + .ok_or(anyhow!("backend doesn't exist at path {path}"))?; let backend = backend_constructor()?; Ok(backend) diff --git a/torrential/src/droplet/manifest.rs b/torrential/src/droplet/manifest.rs index 688a9ce4..b2f11e8c 100644 --- a/torrential/src/droplet/manifest.rs +++ b/torrential/src/droplet/manifest.rs @@ -19,10 +19,9 @@ use crate::{ static READER_SEMAPHORE: LazyLock = LazyLock::new(|| { let cores = std::env::var("READER_THREADS") .ok() - .map(|v| str::parse::(&v).ok()) - .flatten() + .and_then(|v| str::parse::(&v).ok()) .unwrap_or(num_cpus::get() / 2); - info!("using {} import threads", cores); + info!("using {cores} import threads"); Semaphore::new(cores) }); diff --git a/torrential/src/droplet/mod.rs b/torrential/src/droplet/mod.rs index 9b636aac..5909f874 100644 --- a/torrential/src/droplet/mod.rs +++ b/torrential/src/droplet/mod.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use log::{info, warn}; +use log::warn; use crate::{proto::{core::{DropBoundType, TorrentialBound}, droplet::RpcError}, server::DropServer}; @@ -15,7 +15,7 @@ where let message_id = message.message_id.clone(); let result = rpc(server.clone(), message).await; if let Err(err) = result { - warn!("manifest generation failed with err: {:?}", err); + warn!("manifest generation failed with err: {err:?}"); let mut manifest_err = RpcError::new(); manifest_err.error = err.to_string(); let _ = server diff --git a/torrential/src/main.rs b/torrential/src/main.rs index bfdf92e4..45ea7e90 100644 --- a/torrential/src/main.rs +++ b/torrential/src/main.rs @@ -25,7 +25,7 @@ async fn main() { initialise_logger(); if let Ok(working_directory) = std::env::var("WORKING_DIRECTORY") { - info!("moving to working directory {}", working_directory); + info!("moving to working directory {working_directory}"); set_current_dir(working_directory).expect("failed to change working directory"); } @@ -38,7 +38,7 @@ async fn main() { let shared_state = Arc::new(AppState { context_cache: DashMap::new(), - server: server, + server, }); let interval_shared_state = shared_state.clone(); @@ -62,7 +62,7 @@ async fn main() { }; if last_access.elapsed().as_secs() >= CONTEXT_TTL { shared_state.context_cache.remove(&key); - info!("cleaned context: {:?}", key); + info!("cleaned context: {key:?}"); } } } @@ -70,7 +70,7 @@ async fn main() { let app = setup_app(shared_state); - serve(app).await.unwrap(); + serve(app).await.expect("failed to serve app"); } fn setup_app(shared_state: Arc) -> Router { @@ -87,7 +87,9 @@ fn setup_app(shared_state: Arc) -> Router { } async fn serve(app: Router) -> Result<(), std::io::Error> { - let listener = tokio::net::TcpListener::bind("0.0.0.0:5000").await.unwrap(); + let listener = tokio::net::TcpListener::bind("0.0.0.0:5000") + .await + .expect("failed to bind tcp server"); info!("started depot server"); axum::serve(listener, app).await } @@ -96,5 +98,5 @@ fn initialise_logger() { SimpleLogger::new() .with_level(log::LevelFilter::Info) .init() - .unwrap(); + .expect("failed to init logger"); } diff --git a/torrential/src/server/download.rs b/torrential/src/server/download.rs index 6c71aaea..51c1cb2a 100644 --- a/torrential/src/server/download.rs +++ b/torrential/src/server/download.rs @@ -33,5 +33,5 @@ pub async fn fetch_instance_games(app_state: &AppState) -> Result, read_stream: OwnedReadHalf) -> ! { @@ -95,7 +95,7 @@ impl DropServer { loop { if let Err(err) = Self::recieve_loop(myself.clone(), &mut buffered_reader).await { - warn!("server disconnected with error: {:?}", err); + warn!("server disconnected with error: {err:?}"); let (drop_stream, _) = myself .server @@ -130,14 +130,11 @@ impl DropServer { let message = message.value(); - match message.type_.unwrap() { - crate::proto::core::TorrentialBoundType::ERROR => { - return Err(anyhow!(String::from_utf8(message.data.clone()).unwrap())); - } - _ => { - let response = T::parse_from_bytes(&message.data)?; - return Ok(response); - } + if message.type_.unwrap() == crate::proto::core::TorrentialBoundType::ERROR { + Err(anyhow!(String::from_utf8(message.data.clone()).unwrap())) + } else { + let response = T::parse_from_bytes(&message.data)?; + Ok(response) } } diff --git a/torrential/src/state.rs b/torrential/src/state.rs index f55cdc7d..9d2ca0d6 100644 --- a/torrential/src/state.rs +++ b/torrential/src/state.rs @@ -1,7 +1,6 @@ -use std::{collections::HashMap, path::PathBuf, sync::Arc}; +use std::sync::Arc; use dashmap::DashMap; -use tokio::sync::{OnceCell, Semaphore}; use crate::{DownloadContext, server::DropServer};