From 4ac86c085336246d50e1573c79322fb2e286721a Mon Sep 17 00:00:00 2001 From: Chrislearn Young Date: Thu, 19 Sep 2024 12:37:43 +0800 Subject: [PATCH] impl Display and Debug for Text and Json (#912) --- crates/compression/src/lib.rs | 4 +-- crates/core/src/conn/native_tls/config.rs | 4 +-- crates/core/src/conn/openssl/config.rs | 4 +-- crates/core/src/depot.rs | 4 +-- crates/core/src/http/body/channel.rs | 6 ++-- crates/core/src/http/body/req.rs | 6 ++-- crates/core/src/http/body/res.rs | 4 +-- crates/core/src/http/request.rs | 4 +-- crates/core/src/http/response.rs | 4 +-- crates/core/src/routing/filters/mod.rs | 4 +-- crates/core/src/routing/filters/others.rs | 10 +++--- crates/core/src/routing/filters/path.rs | 8 ++--- crates/core/src/routing/router.rs | 4 +-- crates/core/src/server.rs | 1 + crates/core/src/writing/json.rs | 12 ++++++++ crates/core/src/writing/text.rs | 34 +++++++++++++++++++++ crates/cors/src/allow_credentials.rs | 7 +++-- crates/cors/src/allow_headers.rs | 6 ++-- crates/cors/src/allow_methods.rs | 6 ++-- crates/cors/src/allow_origin.rs | 7 +++-- crates/cors/src/expose_headers.rs | 6 ++-- crates/cors/src/max_age.rs | 7 +++-- crates/extra/src/websocket.rs | 6 ++-- crates/oapi/src/extract/parameter/cookie.rs | 12 ++------ crates/oapi/src/extract/parameter/header.rs | 9 ++---- crates/oapi/src/extract/parameter/path.rs | 4 +-- crates/oapi/src/extract/parameter/query.rs | 12 ++------ crates/oapi/src/extract/payload/form.rs | 9 ++---- crates/oapi/src/extract/payload/json.rs | 9 ++---- crates/serde-util/src/case.rs | 4 +-- crates/serve-static/src/dir.rs | 4 +-- 31 files changed, 125 insertions(+), 96 deletions(-) diff --git a/crates/compression/src/lib.rs b/crates/compression/src/lib.rs index b97ca3e64..ba3ac6e19 100644 --- a/crates/compression/src/lib.rs +++ b/crates/compression/src/lib.rs @@ -4,7 +4,7 @@ //! //! Read more: -use std::fmt::{self, Display}; +use std::fmt::{self, Display, Formatter}; use std::str::FromStr; use indexmap::IndexMap; @@ -90,7 +90,7 @@ impl FromStr for CompressionAlgo { impl Display for CompressionAlgo { #[allow(unreachable_patterns)] #[allow(unused_variables)] - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match self { #[cfg(feature = "brotli")] CompressionAlgo::Brotli => write!(f, "br"), diff --git a/crates/core/src/conn/native_tls/config.rs b/crates/core/src/conn/native_tls/config.rs index 14d5fc422..09df76d0f 100644 --- a/crates/core/src/conn/native_tls/config.rs +++ b/crates/core/src/conn/native_tls/config.rs @@ -1,5 +1,5 @@ //! native_tls module -use std::fmt::{self, Formatter}; +use std::fmt::{self, Debug, Formatter}; use std::fs::File; use std::io::{Error as IoError, ErrorKind, Result as IoResult, Read}; use std::path::{Path, PathBuf}; @@ -21,7 +21,7 @@ pub struct NativeTlsConfig { pub password: String, } -impl fmt::Debug for NativeTlsConfig { +impl Debug for NativeTlsConfig { #[inline] fn fmt(&self, f: &mut Formatter) -> fmt::Result { f.debug_struct("NativeTlsConfig").finish() diff --git a/crates/core/src/conn/openssl/config.rs b/crates/core/src/conn/openssl/config.rs index 3fb7a7e5a..8a03386f5 100644 --- a/crates/core/src/conn/openssl/config.rs +++ b/crates/core/src/conn/openssl/config.rs @@ -1,5 +1,5 @@ //! openssl module -use std::fmt::{self, Formatter}; +use std::fmt::{self, Debug, Formatter}; use std::fs::File; use std::future::{Ready, ready}; use std::io::{Error as IoError, Read, Result as IoResult}; @@ -112,7 +112,7 @@ pub struct OpensslConfig { pub alpn_protocols: Vec, } -impl fmt::Debug for OpensslConfig { +impl Debug for OpensslConfig { #[inline] fn fmt(&self, f: &mut Formatter) -> fmt::Result { f.debug_struct("OpensslConfig").finish() diff --git a/crates/core/src/depot.rs b/crates/core/src/depot.rs index b1a0247ee..875ca2e65 100644 --- a/crates/core/src/depot.rs +++ b/crates/core/src/depot.rs @@ -1,6 +1,6 @@ use std::any::{Any, TypeId}; use std::collections::HashMap; -use std::fmt::{self, Formatter}; +use std::fmt::{self, Debug, Formatter}; /// Store temp data for current request. /// @@ -189,7 +189,7 @@ impl Depot { } } -impl fmt::Debug for Depot { +impl Debug for Depot { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { f.debug_struct("Depot") .field("keys", &self.map.keys()) diff --git a/crates/core/src/http/body/channel.rs b/crates/core/src/http/body/channel.rs index 393d46e0d..e94a2cf00 100644 --- a/crates/core/src/http/body/channel.rs +++ b/crates/core/src/http/body/channel.rs @@ -1,4 +1,4 @@ -use std::fmt; +use std::fmt::{self, Debug, Formatter}; use std::io::{Error as IoError, ErrorKind, Result as IoResult}; use std::pin::Pin; use std::task::{Context, Poll}; @@ -148,8 +148,8 @@ impl tokio::io::AsyncWrite for BodySender { } } -impl fmt::Debug for BodySender { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { +impl Debug for BodySender { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { let mut builder = f.debug_tuple("BodySender"); builder.finish() diff --git a/crates/core/src/http/body/req.rs b/crates/core/src/http/body/req.rs index ac8aaf092..34ae94ba2 100644 --- a/crates/core/src/http/body/req.rs +++ b/crates/core/src/http/body/req.rs @@ -1,4 +1,4 @@ -use std::fmt::{self, Formatter}; +use std::fmt::{self, Debug, Formatter}; use std::io::{Error as IoError, ErrorKind, Result as IoResult}; use std::pin::Pin; use std::task::{Context, Poll}; @@ -298,8 +298,8 @@ cfg_feature! { } } -impl fmt::Debug for ReqBody { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { +impl Debug for ReqBody { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match self { ReqBody::None => write!(f, "ReqBody::None"), ReqBody::Once(value) => f.debug_tuple("ReqBody::Once").field(value).finish(), diff --git a/crates/core/src/http/body/res.rs b/crates/core/src/http/body/res.rs index cef706b5b..ab06c5ca9 100644 --- a/crates/core/src/http/body/res.rs +++ b/crates/core/src/http/body/res.rs @@ -1,5 +1,5 @@ use std::collections::VecDeque; -use std::fmt::Debug; +use std::fmt::{self, Debug}; use std::future::Future; use std::io::{Error as IoError, ErrorKind, Result as IoResult}; use std::pin::Pin; @@ -286,7 +286,7 @@ where } impl Debug for ResBody { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> fmt::Result { match self { Self::None => write!(f, "ResBody::None"), Self::Once(value) => f.debug_tuple("ResBody::Once").field(value).finish(), diff --git a/crates/core/src/http/request.rs b/crates/core/src/http/request.rs index 226c404a4..9f7882806 100644 --- a/crates/core/src/http/request.rs +++ b/crates/core/src/http/request.rs @@ -1,6 +1,6 @@ //! HTTP request. use std::error::Error as StdError; -use std::fmt::{self, Formatter}; +use std::fmt::{self, Debug, Formatter}; #[cfg(feature = "quinn")] use std::sync::Arc; use std::sync::OnceLock; @@ -115,7 +115,7 @@ pub struct Request { pub(crate) secure_max_size: Option, } -impl fmt::Debug for Request { +impl Debug for Request { fn fmt(&self, f: &mut Formatter) -> fmt::Result { f.debug_struct("Request") .field("method", self.method()) diff --git a/crates/core/src/http/response.rs b/crates/core/src/http/response.rs index e7c4ec22f..1a1703ab5 100644 --- a/crates/core/src/http/response.rs +++ b/crates/core/src/http/response.rs @@ -1,6 +1,6 @@ //! HTTP response. use std::collections::VecDeque; -use std::fmt::{self, Display, Formatter}; +use std::fmt::{self, Debug, Display, Formatter}; use std::path::PathBuf; #[cfg(feature = "cookie")] @@ -506,7 +506,7 @@ impl Response { } } -impl fmt::Debug for Response { +impl Debug for Response { fn fmt(&self, f: &mut Formatter) -> fmt::Result { f.debug_struct("Response") .field("status_code", &self.status_code) diff --git a/crates/core/src/routing/filters/mod.rs b/crates/core/src/routing/filters/mod.rs index 12df81ea5..d2412a3cc 100644 --- a/crates/core/src/routing/filters/mod.rs +++ b/crates/core/src/routing/filters/mod.rs @@ -7,7 +7,7 @@ mod opts; mod others; mod path; -use std::fmt::{self, Formatter}; +use std::fmt::{self, Debug, Formatter}; use self::opts::*; use crate::http::uri::Scheme; @@ -21,7 +21,7 @@ pub use path::*; /// /// View [module level documentation](../index.html) for more details. -pub trait Filter: fmt::Debug + Send + Sync + 'static { +pub trait Filter: Debug + Send + Sync + 'static { #[doc(hidden)] fn type_id(&self) -> std::any::TypeId { std::any::TypeId::of::() diff --git a/crates/core/src/routing/filters/others.rs b/crates/core/src/routing/filters/others.rs index 672932440..24ff300f8 100644 --- a/crates/core/src/routing/filters/others.rs +++ b/crates/core/src/routing/filters/others.rs @@ -1,4 +1,4 @@ -use std::fmt::{self, Formatter}; +use std::fmt::{self, Debug, Formatter}; use crate::http::uri::Scheme; use crate::http::{Method, Request}; @@ -19,7 +19,7 @@ impl Filter for MethodFilter { req.method() == self.0 } } -impl fmt::Debug for MethodFilter { +impl Debug for MethodFilter { #[inline] fn fmt(&self, f: &mut Formatter) -> fmt::Result { write!(f, "method:{:?}", self.0) @@ -58,7 +58,7 @@ impl Filter for SchemeFilter { .unwrap_or(self.lack) } } -impl fmt::Debug for SchemeFilter { +impl Debug for SchemeFilter { #[inline] fn fmt(&self, f: &mut Formatter) -> fmt::Result { write!(f, "scheme:{:?}", self.scheme) @@ -113,7 +113,7 @@ impl Filter for HostFilter { .unwrap_or(self.lack) } } -impl fmt::Debug for HostFilter { +impl Debug for HostFilter { #[inline] fn fmt(&self, f: &mut Formatter) -> fmt::Result { write!(f, "host:{:?}", self.host) @@ -168,7 +168,7 @@ impl Filter for PortFilter { .unwrap_or(self.lack) } } -impl fmt::Debug for PortFilter { +impl Debug for PortFilter { #[inline] fn fmt(&self, f: &mut Formatter) -> fmt::Result { write!(f, "port:{:?}", self.port) diff --git a/crates/core/src/routing/filters/path.rs b/crates/core/src/routing/filters/path.rs index 18957a32b..294d11edf 100644 --- a/crates/core/src/routing/filters/path.rs +++ b/crates/core/src/routing/filters/path.rs @@ -1,7 +1,7 @@ //! Path filter implementation. use std::collections::HashMap; -use std::fmt::{self, Formatter}; +use std::fmt::{self, Debug, Formatter}; use std::sync::{Arc, LazyLock}; use indexmap::IndexSet; @@ -92,7 +92,7 @@ impl PathWisp for WispKind { } } } -impl fmt::Debug for WispKind { +impl Debug for WispKind { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match self { Self::Const(wisp) => wisp.fmt(f), @@ -240,7 +240,7 @@ pub struct CharsWisp { min_width: usize, max_width: Option, } -impl fmt::Debug for CharsWisp { +impl Debug for CharsWisp { #[inline] fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { write!( @@ -905,7 +905,7 @@ pub struct PathFilter { path_wisps: Vec, } -impl fmt::Debug for PathFilter { +impl Debug for PathFilter { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { write!(f, "path:{}", &self.raw_value) } diff --git a/crates/core/src/routing/router.rs b/crates/core/src/routing/router.rs index eaad92da2..d1e4531bc 100644 --- a/crates/core/src/routing/router.rs +++ b/crates/core/src/routing/router.rs @@ -1,4 +1,4 @@ -use std::fmt::{self, Formatter}; +use std::fmt::{self, Debug, Formatter}; use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::Arc; @@ -337,7 +337,7 @@ const SYMBOL_DOWN: &str = "│"; const SYMBOL_TEE: &str = "├"; const SYMBOL_ELL: &str = "└"; const SYMBOL_RIGHT: &str = "─"; -impl fmt::Debug for Router { +impl Debug for Router { fn fmt(&self, f: &mut Formatter) -> fmt::Result { fn print(f: &mut Formatter, prefix: &str, last: bool, router: &Router) -> fmt::Result { let mut path = "".to_owned(); diff --git a/crates/core/src/server.rs b/crates/core/src/server.rs index c2168405b..cb8f715a3 100644 --- a/crates/core/src/server.rs +++ b/crates/core/src/server.rs @@ -231,6 +231,7 @@ impl Server { /// Try to serve a [`Service`]. #[cfg(feature = "server-handle")] + #[allow(clippy::manual_async_fn)]//Fix: https://github.com/salvo-rs/salvo/issues/902 pub fn try_serve(self, service: S) -> impl Future> + Send where S: Into + Send, diff --git a/crates/core/src/writing/json.rs b/crates/core/src/writing/json.rs index df989698c..b0ba790d0 100644 --- a/crates/core/src/writing/json.rs +++ b/crates/core/src/writing/json.rs @@ -1,3 +1,5 @@ +use std::fmt::{self, Debug, Display, Formatter}; + use async_trait::async_trait; use serde::Serialize; @@ -47,6 +49,16 @@ where } } } +impl Debug for Json { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + f.debug_tuple("Json").field(&self.0).finish() + } +} +impl Display for Json { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + Display::fmt(&self.0, f) + } +} #[cfg(test)] mod tests { diff --git a/crates/core/src/writing/text.rs b/crates/core/src/writing/text.rs index 553fc38bc..7812e558a 100644 --- a/crates/core/src/writing/text.rs +++ b/crates/core/src/writing/text.rs @@ -1,3 +1,5 @@ +use std::fmt::{self, Debug, Display, Formatter}; + use super::Scribe; use crate::http::header::{HeaderValue, CONTENT_TYPE}; use crate::http::Response; @@ -104,6 +106,38 @@ impl<'a> Scribe for Text<&'a String> { res.write_body(content.as_bytes().to_vec()).ok(); } } +impl Debug for Text { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + match self { + Text::Plain(content) => f.debug_tuple("Text::Plain").field(content).finish(), + Text::Json(content) => f.debug_tuple("Text::Json").field(content).finish(), + Text::Xml(content) => f.debug_tuple("Text::Xml").field(content).finish(), + Text::Html(content) => f.debug_tuple("Text::Html").field(content).finish(), + Text::Js(content) => f.debug_tuple("Text::Js").field(content).finish(), + Text::Css(content) => f.debug_tuple("Text::Css").field(content).finish(), + Text::Csv(content) => f.debug_tuple("Text::Csv").field(content).finish(), + Text::Atom(content) => f.debug_tuple("Text::Atom").field(content).finish(), + Text::Rss(content) => f.debug_tuple("Text::Rss").field(content).finish(), + Text::Rdf(content) => f.debug_tuple("Text::Rdf").field(content).finish(), + } + } +} +impl Display for Text { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + match self { + Text::Plain(content) => Display::fmt(content, f), + Text::Json(content) => Display::fmt(content, f), + Text::Xml(content) => Display::fmt(content, f), + Text::Html(content) => Display::fmt(content, f), + Text::Js(content) => Display::fmt(content, f), + Text::Css(content) => Display::fmt(content, f), + Text::Csv(content) => Display::fmt(content, f), + Text::Atom(content) => Display::fmt(content, f), + Text::Rss(content) => Display::fmt(content, f), + Text::Rdf(content) => Display::fmt(content, f), + } + } +} #[cfg(test)] mod tests { diff --git a/crates/cors/src/allow_credentials.rs b/crates/cors/src/allow_credentials.rs index e72e21fbb..382095b2b 100644 --- a/crates/cors/src/allow_credentials.rs +++ b/crates/cors/src/allow_credentials.rs @@ -1,4 +1,5 @@ -use std::{fmt, sync::Arc}; +use std::fmt::{self, Debug, Formatter}; +use std::sync::Arc; use salvo_core::http::header::{self, HeaderName, HeaderValue}; use salvo_core::{Depot, Request}; @@ -69,8 +70,8 @@ impl From for AllowCredentials { } } -impl fmt::Debug for AllowCredentials { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { +impl Debug for AllowCredentials { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match self.0 { AllowCredentialsInner::Yes => f.debug_tuple("Yes").finish(), AllowCredentialsInner::No => f.debug_tuple("No").finish(), diff --git a/crates/cors/src/allow_headers.rs b/crates/cors/src/allow_headers.rs index 38527dbfc..a0530de14 100644 --- a/crates/cors/src/allow_headers.rs +++ b/crates/cors/src/allow_headers.rs @@ -1,4 +1,4 @@ -use std::fmt; +use std::fmt::{self, Debug, Formatter}; use std::str::FromStr; use std::sync::Arc; @@ -93,8 +93,8 @@ impl AllowHeaders { } } -impl fmt::Debug for AllowHeaders { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { +impl Debug for AllowHeaders { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match &self.0 { AllowHeadersInner::None => f.debug_tuple("None").finish(), AllowHeadersInner::Exact(inner) => f.debug_tuple("Exact").field(inner).finish(), diff --git a/crates/cors/src/allow_methods.rs b/crates/cors/src/allow_methods.rs index 54a796ec6..3a8e78ada 100644 --- a/crates/cors/src/allow_methods.rs +++ b/crates/cors/src/allow_methods.rs @@ -1,4 +1,4 @@ -use std::fmt; +use std::fmt::{self, Debug, Formatter}; use std::sync::Arc; use salvo_core::http::header::{self, HeaderName, HeaderValue}; @@ -105,8 +105,8 @@ impl AllowMethods { } } -impl fmt::Debug for AllowMethods { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { +impl Debug for AllowMethods { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match &self.0 { AllowMethodsInner::None => f.debug_tuple("None").finish(), AllowMethodsInner::Exact(inner) => f.debug_tuple("Exact").field(inner).finish(), diff --git a/crates/cors/src/allow_origin.rs b/crates/cors/src/allow_origin.rs index 64038d62a..557318bbc 100644 --- a/crates/cors/src/allow_origin.rs +++ b/crates/cors/src/allow_origin.rs @@ -1,4 +1,5 @@ -use std::{fmt, sync::Arc}; +use std::fmt::{self, Debug, Formatter}; +use std::sync::Arc; use salvo_core::http::header::{self, HeaderName, HeaderValue}; use salvo_core::{Depot, Request}; @@ -98,8 +99,8 @@ impl AllowOrigin { } } -impl fmt::Debug for AllowOrigin { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { +impl Debug for AllowOrigin { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match &self.0 { OriginInner::Exact(inner) => f.debug_tuple("Exact").field(inner).finish(), OriginInner::List(inner) => f.debug_tuple("List").field(inner).finish(), diff --git a/crates/cors/src/expose_headers.rs b/crates/cors/src/expose_headers.rs index 701eb3a96..e9a3a32fb 100644 --- a/crates/cors/src/expose_headers.rs +++ b/crates/cors/src/expose_headers.rs @@ -1,4 +1,4 @@ -use std::fmt; +use std::fmt::{self, Debug, Formatter}; use std::str::FromStr; use std::sync::Arc; @@ -77,8 +77,8 @@ impl ExposeHeaders { } } -impl fmt::Debug for ExposeHeaders { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { +impl Debug for ExposeHeaders { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match &self.0 { ExposeHeadersInner::None => f.debug_tuple("None").finish(), ExposeHeadersInner::Exact(inner) => f.debug_tuple("Exact").field(inner).finish(), diff --git a/crates/cors/src/max_age.rs b/crates/cors/src/max_age.rs index 4aa90bc24..6ddb03e28 100644 --- a/crates/cors/src/max_age.rs +++ b/crates/cors/src/max_age.rs @@ -1,4 +1,5 @@ -use std::{fmt, sync::Arc, time::Duration}; +use std::fmt::{self, Debug, Formatter}; +use std::{sync::Arc, time::Duration}; use salvo_core::http::header::{self, HeaderName, HeaderValue}; use salvo_core::{Depot, Request}; @@ -57,8 +58,8 @@ impl MaxAge { } } -impl fmt::Debug for MaxAge { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { +impl Debug for MaxAge { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match &self.0 { MaxAgeInner::None => f.debug_tuple("None").finish(), MaxAgeInner::Exact(inner) => f.debug_tuple("Exact").field(inner).finish(), diff --git a/crates/extra/src/websocket.rs b/crates/extra/src/websocket.rs index 9034355ee..de9676ac7 100644 --- a/crates/extra/src/websocket.rs +++ b/crates/extra/src/websocket.rs @@ -78,7 +78,7 @@ //!``` use std::borrow::Cow; -use std::fmt::{self, Formatter}; +use std::fmt::{self, Debug, Formatter}; use std::future::Future; use std::pin::Pin; use std::task::{Context, Poll, ready}; @@ -345,7 +345,7 @@ impl Sink for WebSocket { } } -impl fmt::Debug for WebSocket { +impl Debug for WebSocket { #[inline] fn fmt(&self, f: &mut Formatter) -> fmt::Result { f.debug_struct("WebSocket").finish() @@ -482,7 +482,7 @@ impl Message { } } -impl fmt::Debug for Message { +impl Debug for Message { #[inline] fn fmt(&self, f: &mut Formatter) -> fmt::Result { fmt::Debug::fmt(&self.inner, f) diff --git a/crates/oapi/src/extract/parameter/cookie.rs b/crates/oapi/src/extract/parameter/cookie.rs index 6ccb7ca99..3c73d8dac 100644 --- a/crates/oapi/src/extract/parameter/cookie.rs +++ b/crates/oapi/src/extract/parameter/cookie.rs @@ -1,4 +1,4 @@ -use std::fmt::{self, Formatter}; +use std::fmt::{self, Debug, Display, Formatter}; use std::ops::{Deref, DerefMut}; use salvo_core::extract::{Extractible, Metadata}; @@ -67,19 +67,13 @@ where } } -impl fmt::Debug for CookieParam -where - T: fmt::Debug, -{ +impl fmt::Debug for CookieParam { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { self.0.fmt(f) } } -impl fmt::Display for CookieParam -where - T: fmt::Display, -{ +impl Display for CookieParam { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { self.0 .as_ref() diff --git a/crates/oapi/src/extract/parameter/header.rs b/crates/oapi/src/extract/parameter/header.rs index b2faf8115..5ebb1dab2 100644 --- a/crates/oapi/src/extract/parameter/header.rs +++ b/crates/oapi/src/extract/parameter/header.rs @@ -1,4 +1,4 @@ -use std::fmt::{self, Formatter}; +use std::fmt::{self, Debug, Display, Formatter}; use std::ops::{Deref, DerefMut}; use salvo_core::extract::{Extractible, Metadata}; @@ -79,16 +79,13 @@ where impl fmt::Debug for HeaderParam where - T: fmt::Debug, + T: Debug, { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { self.0.fmt(f) } } -impl fmt::Display for HeaderParam -where - T: fmt::Display, -{ +impl Display for HeaderParam { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { self.0 .as_ref() diff --git a/crates/oapi/src/extract/parameter/path.rs b/crates/oapi/src/extract/parameter/path.rs index dba2ab2f1..9279c4180 100644 --- a/crates/oapi/src/extract/parameter/path.rs +++ b/crates/oapi/src/extract/parameter/path.rs @@ -1,4 +1,4 @@ -use std::fmt::{self, Formatter}; +use std::fmt::{self, Debug, Formatter}; use std::ops::{Deref, DerefMut}; use salvo_core::extract::{Extractible, Metadata}; @@ -45,7 +45,7 @@ where impl fmt::Debug for PathParam where - T: fmt::Debug, + T: Debug, { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { self.0.fmt(f) diff --git a/crates/oapi/src/extract/parameter/query.rs b/crates/oapi/src/extract/parameter/query.rs index 86877573a..74cdeafa4 100644 --- a/crates/oapi/src/extract/parameter/query.rs +++ b/crates/oapi/src/extract/parameter/query.rs @@ -1,4 +1,4 @@ -use std::fmt::{self, Formatter}; +use std::fmt::{self, Debug, Display, Formatter}; use std::ops::{Deref, DerefMut}; use salvo_core::extract::{Extractible, Metadata}; @@ -66,19 +66,13 @@ where } } -impl fmt::Debug for QueryParam -where - T: fmt::Debug, -{ +impl Debug for QueryParam { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { self.0.fmt(f) } } -impl fmt::Display for QueryParam -where - T: fmt::Display, -{ +impl Display for QueryParam { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { self.0 .as_ref() diff --git a/crates/oapi/src/extract/payload/form.rs b/crates/oapi/src/extract/payload/form.rs index 6286f6715..a2ae3a9fd 100644 --- a/crates/oapi/src/extract/payload/form.rs +++ b/crates/oapi/src/extract/payload/form.rs @@ -1,4 +1,4 @@ -use std::fmt::{self, Formatter}; +use std::fmt::{self, Debug, Display, Formatter}; use std::ops::{Deref, DerefMut}; use salvo_core::extract::{Extractible, Metadata}; @@ -48,17 +48,14 @@ where impl fmt::Debug for FormBody where - T: fmt::Debug, + T: Debug, { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { self.0.fmt(f) } } -impl fmt::Display for FormBody -where - T: fmt::Display, -{ +impl Display for FormBody { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { self.0.fmt(f) } diff --git a/crates/oapi/src/extract/payload/json.rs b/crates/oapi/src/extract/payload/json.rs index fb39903c1..06a6d4e05 100644 --- a/crates/oapi/src/extract/payload/json.rs +++ b/crates/oapi/src/extract/payload/json.rs @@ -1,4 +1,4 @@ -use std::fmt::{self, Formatter}; +use std::fmt::{self, Debug, Display, Formatter}; use std::ops::{Deref, DerefMut}; use salvo_core::extract::{Extractible, Metadata}; @@ -44,17 +44,14 @@ where impl fmt::Debug for JsonBody where - T: fmt::Debug, + T: Debug, { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { self.0.fmt(f) } } -impl fmt::Display for JsonBody -where - T: fmt::Display, -{ +impl Display for JsonBody { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { self.0.fmt(f) } diff --git a/crates/serde-util/src/case.rs b/crates/serde-util/src/case.rs index f1a9973b8..c2b815511 100644 --- a/crates/serde-util/src/case.rs +++ b/crates/serde-util/src/case.rs @@ -1,7 +1,7 @@ //! Code to convert the Rust-styled field/variant (e.g. `my_field`, `MyType`) to the //! case of the source (e.g. `my-field`, `MY_FIELD`). -use std::fmt::{self, Debug, Display}; +use std::fmt::{self, Debug, Display, Formatter}; use std::str::FromStr; use proc_macro2::Span; @@ -45,7 +45,7 @@ pub(crate) const RENAME_RULES: [(&str, RenameRule); 8] = [ ]; impl Display for RenameRule { - fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { + fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result { formatter.write_str(match self { LowerCase => "lowercase", UpperCase => "UPPERCASE", diff --git a/crates/serve-static/src/dir.rs b/crates/serve-static/src/dir.rs index a6eb39ab7..427bb092a 100644 --- a/crates/serve-static/src/dir.rs +++ b/crates/serve-static/src/dir.rs @@ -2,7 +2,7 @@ use std::collections::{HashMap, HashSet}; use std::ffi::OsStr; -use std::fmt::{self, Display, Write}; +use std::fmt::{self, Display, Formatter, Write}; use std::fs::Metadata; use std::path::{Path, PathBuf}; use std::str::FromStr; @@ -51,7 +51,7 @@ impl FromStr for CompressionAlgo { } impl Display for CompressionAlgo { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match self { Self::Brotli => write!(f, "br"), Self::Deflate => write!(f, "deflate"),