From 93bf38ec03ec37e76efc485d384e83cefd30a180 Mon Sep 17 00:00:00 2001 From: _ <> Date: Sun, 2 May 2021 22:32:24 +0000 Subject: [PATCH] :rotating_light: clippy pass --- crates/ptth_relay/src/config.rs | 6 +++--- crates/ptth_relay/src/lib.rs | 11 +++++------ crates/ptth_relay/src/relay_state.rs | 2 +- crates/ptth_relay/src/routing.rs | 3 +-- crates/ptth_server/src/file_server.rs | 16 ++++++++-------- crates/ptth_server/src/lib.rs | 4 ++-- 6 files changed, 20 insertions(+), 22 deletions(-) diff --git a/crates/ptth_relay/src/config.rs b/crates/ptth_relay/src/config.rs index 3e2c0d3..7536170 100644 --- a/crates/ptth_relay/src/config.rs +++ b/crates/ptth_relay/src/config.rs @@ -21,7 +21,7 @@ use crate::{ /// Machine-editable configs. /// These are stored in the `data` directory and shouldn't be touched by -/// humans. ptth_relay will re-write them while it's running. +/// humans. `ptth_relay` will re-write them while it's running. pub mod machine_editable { use std::{ @@ -196,7 +196,7 @@ impl TryFrom for Config { port: f.port, servers, scraper_keys, - news_url: f.news_url.clone (), + news_url: f.news_url, }) } } @@ -205,7 +205,7 @@ fn parse_address (s: Option <&str>) -> Result { Ok (s .map (|s| IpAddr::from_str (s)) .transpose ().map_err (|_| ConfigError::BadServerAddress)? - .unwrap_or (IpAddr::from ([0, 0, 0, 0])) + .unwrap_or_else (|| IpAddr::from ([0, 0, 0, 0])) ) } diff --git a/crates/ptth_relay/src/lib.rs b/crates/ptth_relay/src/lib.rs index f69cf32..ea6c9c5 100644 --- a/crates/ptth_relay/src/lib.rs +++ b/crates/ptth_relay/src/lib.rs @@ -105,7 +105,7 @@ fn error_reply (status: StatusCode, b: &str) fn get_user_name (req: &http::request::Parts) -> Option { - req.headers.get ("X-Email").map (|x| Some (x.to_str ().ok ()?.to_string ())).flatten () + req.headers.get ("X-Email").and_then (|x| Some (x.to_str ().ok ()?.to_string ())) } /// Clients will come here to start requests, and always park for at least @@ -371,7 +371,7 @@ async fn handle_unregistered_servers_internal (state: &Relay) } server_list.sort_by_key (|s| { - (s.name.clone (), s.tripcode.as_bytes ().clone (), now - s.seen) + (s.name.clone (), *s.tripcode.as_bytes (), now - s.seen) }); server_list.dedup_by_key (|s| { (s.name.clone (), s.tripcode) @@ -669,13 +669,13 @@ async fn check_server_api_key (state: &Relay, name: &str, api_key: &[u8]) let expected_human = { let config = state.config.read ().await; - config.servers.get (name).map (|s| s.tripcode.clone ()) + config.servers.get (name).map (|s| s.tripcode) }; let expected_machine = { let me_config = state.me_config.read ().await; - me_config.servers.get (name).map (|s| s.tripcode.clone ()) + me_config.servers.get (name).map (|s| s.tripcode) }; if expected_machine.is_none () && expected_human.is_none () { @@ -793,8 +793,7 @@ pub async fn run_relay ( let status_code = match &e { UnknownServer => StatusCode::NOT_FOUND, BadRequest => StatusCode::BAD_REQUEST, - ServerNeverResponded => StatusCode::GATEWAY_TIMEOUT, - ServerTimedOut => StatusCode::GATEWAY_TIMEOUT, + ServerNeverResponded | ServerTimedOut => StatusCode::GATEWAY_TIMEOUT, _ => StatusCode::INTERNAL_SERVER_ERROR, }; diff --git a/crates/ptth_relay/src/relay_state.rs b/crates/ptth_relay/src/relay_state.rs index 1d5cd4c..8bd0870 100644 --- a/crates/ptth_relay/src/relay_state.rs +++ b/crates/ptth_relay/src/relay_state.rs @@ -228,7 +228,7 @@ impl Relay { false } - + #[must_use] pub fn build () -> Builder { Builder::default () } diff --git a/crates/ptth_relay/src/routing.rs b/crates/ptth_relay/src/routing.rs index ff8ccf7..f692758 100644 --- a/crates/ptth_relay/src/routing.rs +++ b/crates/ptth_relay/src/routing.rs @@ -63,11 +63,10 @@ pub fn route_url <'a> (method: &Method, path: &'a str) -> Route <'a> { } else if let Some (idx) = rest.find ('/') { let listen_code = &rest [0..idx]; - let path = &rest [idx..]; Route::ClientServerGet { listen_code, - path, + path: &rest [idx..], } } else { diff --git a/crates/ptth_server/src/file_server.rs b/crates/ptth_server/src/file_server.rs index 3ddf654..4c4d301 100644 --- a/crates/ptth_server/src/file_server.rs +++ b/crates/ptth_server/src/file_server.rs @@ -202,9 +202,9 @@ async fn serve_file ( // consider it stale. response.header ("cache-control".to_string (), b"no-cache,max-age=0".to_vec ()); - input.actual_etag.map (|etag| { + if let Some (etag) = input.actual_etag { response.header ("etag".to_string (), etag); - }); + }; response.header (String::from ("accept-ranges"), b"bytes".to_vec ()); if range_requested { @@ -236,14 +236,14 @@ struct ServeFileOutput { fn serve_file_decision (input: &ServeFileInput) -> ServeFileOutput { - match (&input.if_none_match, &input.actual_etag) { - (Some (if_none_match), Some (actual_etag)) => if &actual_etag == if_none_match { + if let (Some (if_none_match), Some (actual_etag)) = (&input.if_none_match, &input.actual_etag) + { + if actual_etag == if_none_match { return ServeFileOutput { status_code: StatusCode::NotModified, should_send_body: false, }; - }, - _ => (), + } } if ! input.client_wants_body { @@ -268,14 +268,14 @@ fn serve_file_decision (input: &ServeFileInput) -> ServeFileOutput async fn get_file_etag (f: &File) -> Option { - let md = f.metadata ().await.ok ()?; - #[derive (Serialize)] struct CacheBreaker { len: u64, mtime: std::time::SystemTime, } + let md = f.metadata ().await.ok ()?; + let buf = rmp_serde::to_vec (&CacheBreaker { len: md.len (), mtime: md.modified ().ok ()?, diff --git a/crates/ptth_server/src/lib.rs b/crates/ptth_server/src/lib.rs index 0e20307..26f91c8 100644 --- a/crates/ptth_server/src/lib.rs +++ b/crates/ptth_server/src/lib.rs @@ -185,7 +185,7 @@ async fn handle_req_resp ( Ok (()) } -/// Config for ptth_server and the file server module +/// Config for `ptth_server` and the file server module /// /// This is a complete config. /// The bin frontend is allowed to load an incomplete config from @@ -230,7 +230,7 @@ impl ConfigFile { } } -/// Config for ptth_server itself +/// Config for `ptth_server` itself #[derive (Default)] pub struct Config {