From 66fd940c1549181ab2951e3b29f455640bab9c61 Mon Sep 17 00:00:00 2001 From: eternal-flame-AD Date: Wed, 16 Oct 2024 21:01:54 -0500 Subject: [PATCH] Clippy suggestions Signed-off-by: eternal-flame-AD --- src/evaluate/chain/audit.rs | 7 +++---- src/evaluate/chain/meta.rs | 1 + src/evaluate/mod.rs | 8 ++++---- src/lib.rs | 12 ++++-------- src/main.rs | 2 +- 5 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/evaluate/chain/audit.rs b/src/evaluate/chain/audit.rs index 7802107..2f44b23 100644 --- a/src/evaluate/chain/audit.rs +++ b/src/evaluate/chain/audit.rs @@ -1,11 +1,10 @@ use axum::response::IntoResponse; use flate2::write::GzEncoder; -use flate2::{Compression, GzBuilder}; +use flate2::Compression; use reqwest::Url; use serde::Serialize; use std::collections::HashSet; use std::fs::{File, OpenOptions}; -use std::io::{BufReader, BufWriter}; use std::sync::atomic::AtomicU32; use std::{collections::HashMap, fmt::Debug, ops::DerefMut, path::PathBuf, sync::Arc}; use tokio::sync::{Mutex, RwLock}; @@ -118,9 +117,9 @@ impl AuditState { let file = OpenOptions::new() .create(true) - .write(true) + .append(true) - .open(&self.options.output.join(&full_name))?; + .open(self.options.output.join(&full_name))?; let gz = GzEncoder::new(file, Compression::default()); diff --git a/src/evaluate/chain/meta.rs b/src/evaluate/chain/meta.rs index fd5f5fd..20811f5 100644 --- a/src/evaluate/chain/meta.rs +++ b/src/evaluate/chain/meta.rs @@ -75,6 +75,7 @@ impl< ctx: Option, info: &APRequestInfo<'r>, ) -> (Disposition, Option) { + #[allow(clippy::unwrap_used)] let ctx = ctx.map(|mut c| { c["meta"] = serde_json::to_value(extract_meta(info)).unwrap(); c diff --git a/src/evaluate/mod.rs b/src/evaluate/mod.rs index 6b56f5c..a9c8d9e 100644 --- a/src/evaluate/mod.rs +++ b/src/evaluate/mod.rs @@ -7,7 +7,7 @@ pub mod chain; #[macro_export] macro_rules! delegate { (state $str:ident::.$field:ident) => { - use crate::{BaseAppState, ClientCache}; + use $crate::{BaseAppState, ClientCache}; impl> HasAppState for $str:: { fn app_state(&self) -> &BaseAppState { self.inner.app_state() @@ -75,9 +75,9 @@ pub trait Evaluator { ) -> (Disposition, Option); } -impl Into> for Result<(), E> { - fn into(self) -> Disposition { - match self { +impl From> for Disposition { + fn from(val: Result<(), E>) -> Self { + match val { Ok(()) => Disposition::Next, Err(e) => Disposition::Intercept(e), } diff --git a/src/lib.rs b/src/lib.rs index 8fecfff..56a6c7b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -27,7 +27,6 @@ use model::ap::AnyObject; use model::{ap, error::MisskeyError}; use network::stream::LimitedStream; use network::{new_backend_client, Either}; -use reqwest; use serde::ser::{SerializeMap, SerializeStruct}; use serde::Serialize; @@ -126,7 +125,7 @@ pub struct BaseAppState { impl HasAppState for Arc> { fn app_state(&self) -> &BaseAppState { - &self + self } fn client_pool_ref(&self) -> &ClientCache { @@ -307,10 +306,7 @@ impl< }; let ctx = app.app_state().ctx_template.clone(); - match app.evaluate(ctx, &info).await.0 { - Disposition::Intercept(e) => return Err(Either::B(e)), - _ => {} - } + if let Disposition::Intercept(e) = app.evaluate(ctx, &info).await.0 { return Err(Either::B(e)) } header.remove("host"); @@ -353,7 +349,7 @@ impl< .ok_or(Either::A(ERR_INTERNAL_SERVER_ERROR))? .extend(resp.headers().clone()); - Ok(resp_builder + resp_builder .header("X-Forwarded-For", addr.to_string()) .body(Body::from_stream(resp.bytes_stream().inspect_err(|e| { log::error!("Failed to read response: {}", e); @@ -361,6 +357,6 @@ impl< .map_err(|e| { log::error!("Failed to build response: {}", e); Either::A(ERR_SERVICE_TEMPORARILY_UNAVAILABLE) - })?) + }) } } diff --git a/src/main.rs b/src/main.rs index 22f632e..1b35320 100644 --- a/src/main.rs +++ b/src/main.rs @@ -59,5 +59,5 @@ async fn main() { ) .await, ) - .await; + .await }