From 3ee88662c53e37ed18c24e84a753dc7450a7c628 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Mon, 11 Sep 2023 18:04:36 +0600 Subject: [PATCH] Add missing fmt::Debug impls --- ntex-connect/CHANGES.md | 4 +++ ntex-connect/Cargo.toml | 6 ++-- ntex-connect/src/lib.rs | 2 ++ ntex-connect/src/openssl.rs | 11 ++++++- ntex-connect/src/rustls.rs | 10 +++++- ntex-connect/src/service.rs | 19 ++++++++++- ntex-io/CHANGES.md | 4 +++ ntex-io/Cargo.toml | 6 ++-- ntex-io/src/buf.rs | 40 +++++++++++++++++------ ntex-io/src/dispatcher.rs | 3 +- ntex-io/src/filter.rs | 2 ++ ntex-io/src/io.rs | 22 +++++++++++-- ntex-io/src/ioref.rs | 2 +- ntex-io/src/lib.rs | 2 ++ ntex-io/src/seal.rs | 8 ++++- ntex-io/src/tasks.rs | 2 ++ ntex-io/src/types.rs | 10 ++++++ ntex-io/src/utils.rs | 18 ++++++++++- ntex-tls/CHANGES.md | 4 +++ ntex-tls/Cargo.toml | 8 ++--- ntex-tls/src/counter.rs | 9 +++--- ntex-tls/src/lib.rs | 2 ++ ntex-tls/src/openssl/accept.rs | 2 ++ ntex-tls/src/openssl/mod.rs | 13 +++++++- ntex-tls/src/rustls/accept.rs | 2 ++ ntex-tls/src/rustls/client.rs | 3 +- ntex-tls/src/rustls/mod.rs | 6 ++++ ntex-tls/src/rustls/server.rs | 3 +- ntex-util/CHANGES.md | 6 +++- ntex-util/Cargo.toml | 4 +-- ntex-util/src/channel/cell.rs | 1 + ntex-util/src/channel/condition.rs | 4 ++- ntex-util/src/channel/mpsc.rs | 1 + ntex-util/src/lib.rs | 2 ++ ntex-util/src/services/buffer.rs | 47 +++++++++++++++++++++------- ntex-util/src/services/counter.rs | 3 ++ ntex-util/src/services/inflight.rs | 1 + ntex-util/src/services/keepalive.rs | 21 ++++++++++++- ntex-util/src/services/onerequest.rs | 1 + ntex-util/src/services/variant.rs | 33 +++++++++++++++++-- ntex-util/src/task.rs | 6 ++++ ntex/CHANGES.md | 4 +++ ntex/Cargo.toml | 8 ++--- ntex/src/http/client/builder.rs | 5 ++- ntex/src/http/client/connect.rs | 18 +++++++++-- ntex/src/http/client/connector.rs | 9 ++++-- ntex/src/http/client/mod.rs | 5 +-- ntex/src/http/client/pool.rs | 3 ++ ntex/src/lib.rs | 2 +- ntex/src/web/types/json.rs | 15 +++++++++ ntex/src/ws/sink.rs | 3 +- ntex/src/ws/transport.rs | 2 ++ 52 files changed, 358 insertions(+), 69 deletions(-) diff --git a/ntex-connect/CHANGES.md b/ntex-connect/CHANGES.md index f4d5518ad..77ebf8320 100644 --- a/ntex-connect/CHANGES.md +++ b/ntex-connect/CHANGES.md @@ -1,5 +1,9 @@ # Changes +## [0.3.1] - 2023-09-11 + +* Add missing fmt::Debug impls + ## [0.3.0] - 2023-06-22 * Release v0.3.0 diff --git a/ntex-connect/Cargo.toml b/ntex-connect/Cargo.toml index 0e3af423d..d34004fce 100644 --- a/ntex-connect/Cargo.toml +++ b/ntex-connect/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ntex-connect" -version = "0.3.0" +version = "0.3.1" authors = ["ntex contributors "] description = "ntexwork connect utils for ntex framework" keywords = ["network", "framework", "async", "futures"] @@ -34,13 +34,13 @@ glommio = ["ntex-rt/glommio", "ntex-glommio"] async-std = ["ntex-rt/async-std", "ntex-async-std"] [dependencies] -ntex-service = "1.2.0" +ntex-service = "1.2.6" ntex-bytes = "0.1.19" ntex-http = "0.1.8" ntex-io = "0.3.0" ntex-rt = "0.4.7" ntex-tls = "0.3.0" -ntex-util = "0.3.0" +ntex-util = "0.3.2" log = "0.4" thiserror = "1.0" diff --git a/ntex-connect/src/lib.rs b/ntex-connect/src/lib.rs index 6fd06ce80..5d6455fe1 100644 --- a/ntex-connect/src/lib.rs +++ b/ntex-connect/src/lib.rs @@ -1,4 +1,6 @@ //! Tcp connector service +#![deny(rust_2018_idioms, unreachable_pub, missing_debug_implementations)] + #[macro_use] extern crate log; diff --git a/ntex-connect/src/openssl.rs b/ntex-connect/src/openssl.rs index 03f385f87..eb52e77d9 100644 --- a/ntex-connect/src/openssl.rs +++ b/ntex-connect/src/openssl.rs @@ -1,4 +1,4 @@ -use std::io; +use std::{fmt, io}; pub use ntex_tls::openssl::SslFilter; pub use tls_openssl::ssl::{Error as SslError, HandshakeError, SslConnector, SslMethod}; @@ -88,6 +88,15 @@ impl Clone for Connector { } } +impl fmt::Debug for Connector { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Connector(openssl)") + .field("connector", &self.connector) + .field("openssl", &self.openssl) + .finish() + } +} + impl ServiceFactory, C> for Connector { type Response = Io>; type Error = ConnectError; diff --git a/ntex-connect/src/rustls.rs b/ntex-connect/src/rustls.rs index fc6dbe6ef..3771dcf74 100644 --- a/ntex-connect/src/rustls.rs +++ b/ntex-connect/src/rustls.rs @@ -1,4 +1,4 @@ -use std::io; +use std::{fmt, io}; pub use ntex_tls::rustls::TlsFilter; pub use tls_rustls::{ClientConfig, ServerName}; @@ -92,6 +92,14 @@ impl Clone for Connector { } } +impl fmt::Debug for Connector { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Connector(rustls)") + .field("connector", &self.connector) + .finish() + } +} + impl ServiceFactory, C> for Connector { type Response = Io>; type Error = ConnectError; diff --git a/ntex-connect/src/service.rs b/ntex-connect/src/service.rs index 74839b50d..b8c4dbde4 100644 --- a/ntex-connect/src/service.rs +++ b/ntex-connect/src/service.rs @@ -1,5 +1,5 @@ use std::task::{Context, Poll}; -use std::{collections::VecDeque, future::Future, io, net::SocketAddr, pin::Pin}; +use std::{collections::VecDeque, fmt, future::Future, io, net::SocketAddr, pin::Pin}; use ntex_bytes::{PoolId, PoolRef}; use ntex_io::{types, Io}; @@ -61,6 +61,15 @@ impl Clone for Connector { } } +impl fmt::Debug for Connector { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Connector") + .field("resolver", &self.resolver) + .field("memory_pool", &self.pool) + .finish() + } +} + impl ServiceFactory, C> for Connector { type Response = Io; type Error = ConnectError; @@ -105,6 +114,14 @@ impl<'f, T: Address> ConnectServiceResponse<'f, T> { } } +impl<'f, T: Address> fmt::Debug for ConnectServiceResponse<'f, T> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("ConnectServiceResponse") + .field("pool", &self.pool) + .finish() + } +} + impl<'f, T: Address> Future for ConnectServiceResponse<'f, T> { type Output = Result; diff --git a/ntex-io/CHANGES.md b/ntex-io/CHANGES.md index 3255e9d3f..3abbb537c 100644 --- a/ntex-io/CHANGES.md +++ b/ntex-io/CHANGES.md @@ -1,5 +1,9 @@ # Changes +## [0.3.3] - 2023-09-11 + +* Add missing fmt::Debug impls + ## [0.3.2] - 2023-08-10 * Replace `PipelineCall` with `ServiceCall<'static, S, R>` diff --git a/ntex-io/Cargo.toml b/ntex-io/Cargo.toml index 7c3aa37a6..86bb6d72e 100644 --- a/ntex-io/Cargo.toml +++ b/ntex-io/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ntex-io" -version = "0.3.2" +version = "0.3.3" authors = ["ntex contributors "] description = "Utilities for encoding and decoding frames" keywords = ["network", "framework", "async", "futures"] @@ -18,8 +18,8 @@ path = "src/lib.rs" [dependencies] ntex-codec = "0.6.2" ntex-bytes = "0.1.19" -ntex-util = "0.3.0" -ntex-service = "1.2.3" +ntex-util = "0.3.2" +ntex-service = "1.2.6" bitflags = "1.3" log = "0.4" diff --git a/ntex-io/src/buf.rs b/ntex-io/src/buf.rs index 36425f567..1481d7b46 100644 --- a/ntex-io/src/buf.rs +++ b/ntex-io/src/buf.rs @@ -1,12 +1,29 @@ -use std::cell::Cell; +use std::{cell::Cell, fmt}; use ntex_bytes::{BytesVec, PoolRef}; use ntex_util::future::Either; use crate::IoRef; -type Buffer = (Cell>, Cell>); +#[derive(Default)] +pub(crate) struct Buffer(Cell>, Cell>); + +impl fmt::Debug for Buffer { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let b0 = self.0.take(); + let b1 = self.1.take(); + let res = f + .debug_struct("Buffer") + .field("0", &b0) + .field("1", &b1) + .finish(); + self.0.set(b0); + self.1.set(b1); + res + } +} +#[derive(Debug)] pub struct Stack { len: usize, buffers: Either<[Buffer; 3], Vec>, @@ -25,29 +42,32 @@ impl Stack { Either::Left(b) => { // move to vec if self.len == 3 { - let mut vec = vec![(Cell::new(None), Cell::new(None))]; + let mut vec = vec![Buffer(Cell::new(None), Cell::new(None))]; for item in b.iter_mut().take(self.len) { - vec.push((Cell::new(item.0.take()), Cell::new(item.1.take()))); + vec.push(Buffer( + Cell::new(item.0.take()), + Cell::new(item.1.take()), + )); } self.len += 1; self.buffers = Either::Right(vec); } else { let mut idx = self.len; while idx > 0 { - let item = ( + let item = Buffer( Cell::new(b[idx - 1].0.take()), Cell::new(b[idx - 1].1.take()), ); b[idx] = item; idx -= 1; } - b[0] = (Cell::new(None), Cell::new(None)); + b[0] = Buffer(Cell::new(None), Cell::new(None)); self.len += 1; } } Either::Right(vec) => { self.len += 1; - vec.insert(0, (Cell::new(None), Cell::new(None))); + vec.insert(0, Buffer(Cell::new(None), Cell::new(None))); } } } @@ -65,8 +85,8 @@ impl Stack { if self.len > next { f(&buffers[idx], &buffers[next]) } else { - let curr = (Cell::new(buffers[idx].0.take()), Cell::new(None)); - let next = (Cell::new(None), Cell::new(buffers[idx].1.take())); + let curr = Buffer(Cell::new(buffers[idx].0.take()), Cell::new(None)); + let next = Buffer(Cell::new(None), Cell::new(buffers[idx].1.take())); let result = f(&curr, &next); buffers[idx].0.set(curr.0.take()); @@ -265,6 +285,7 @@ impl Stack { } } +#[derive(Debug)] pub struct ReadBuf<'a> { pub(crate) io: &'a IoRef, pub(crate) curr: &'a Buffer, @@ -403,6 +424,7 @@ impl<'a> ReadBuf<'a> { } } +#[derive(Debug)] pub struct WriteBuf<'a> { pub(crate) io: &'a IoRef, pub(crate) curr: &'a Buffer, diff --git a/ntex-io/src/dispatcher.rs b/ntex-io/src/dispatcher.rs index 884b68db0..5f2d48899 100644 --- a/ntex-io/src/dispatcher.rs +++ b/ntex-io/src/dispatcher.rs @@ -44,7 +44,7 @@ where pool: Pool, } -pub struct DispatcherShared +pub(crate) struct DispatcherShared where S: Service, Response = Option>>, U: Encoder + Decoder, @@ -64,6 +64,7 @@ enum DispatcherState { Shutdown, } +#[derive(Debug)] enum DispatcherError { Encoder(U), Service(S), diff --git a/ntex-io/src/filter.rs b/ntex-io/src/filter.rs index 7536d1fb7..9f8593ecd 100644 --- a/ntex-io/src/filter.rs +++ b/ntex-io/src/filter.rs @@ -2,6 +2,7 @@ use std::{any, io, task::Context, task::Poll}; use super::{buf::Stack, io::Flags, FilterLayer, IoRef, ReadStatus, WriteStatus}; +#[derive(Debug)] /// Default `Io` filter pub struct Base(IoRef); @@ -11,6 +12,7 @@ impl Base { } } +#[derive(Debug)] pub struct Layer(pub(crate) F, L); impl Layer { diff --git a/ntex-io/src/io.rs b/ntex-io/src/io.rs index 96779af47..5daf1deb1 100644 --- a/ntex-io/src/io.rs +++ b/ntex-io/src/io.rs @@ -153,6 +153,23 @@ impl Drop for IoState { } } +impl fmt::Debug for IoState { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let err = self.error.take(); + let res = f + .debug_struct("IoState") + .field("flags", &self.flags) + .field("pool", &self.pool) + .field("disconnect_timeout", &self.disconnect_timeout) + .field("error", &err) + .field("buffer", &self.buffer) + .field("keepalive", &self.keepalive) + .finish(); + self.error.set(err); + res + } +} + impl Io { #[inline] /// Create `Io` instance @@ -601,9 +618,7 @@ impl hash::Hash for Io { impl fmt::Debug for Io { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("Io") - .field("open", &!self.is_closed()) - .finish() + f.debug_struct("Io").field("state", &self.0).finish() } } @@ -771,6 +786,7 @@ impl FilterItem { } } +#[derive(Debug)] /// OnDisconnect future resolves when socket get disconnected #[must_use = "OnDisconnect do nothing unless polled"] pub struct OnDisconnect { diff --git a/ntex-io/src/ioref.rs b/ntex-io/src/ioref.rs index d8d9944c8..c78b6429f 100644 --- a/ntex-io/src/ioref.rs +++ b/ntex-io/src/ioref.rs @@ -236,7 +236,7 @@ impl hash::Hash for IoRef { impl fmt::Debug for IoRef { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("IoRef") - .field("open", &!self.is_closed()) + .field("state", self.0.as_ref()) .finish() } } diff --git a/ntex-io/src/lib.rs b/ntex-io/src/lib.rs index 1bba316b8..13f51769f 100644 --- a/ntex-io/src/lib.rs +++ b/ntex-io/src/lib.rs @@ -1,4 +1,6 @@ //! Utilities for abstructing io streams +#![deny(rust_2018_idioms, unreachable_pub, missing_debug_implementations)] + use std::{ any::Any, any::TypeId, fmt, future::Future, io as sio, io::Error as IoError, task::Context, task::Poll, diff --git a/ntex-io/src/seal.rs b/ntex-io/src/seal.rs index 018da2569..12a527f41 100644 --- a/ntex-io/src/seal.rs +++ b/ntex-io/src/seal.rs @@ -1,10 +1,16 @@ -use std::ops; +use std::{fmt, ops}; use crate::{filter::Filter, Io}; /// Sealed filter type pub struct Sealed(pub(crate) Box); +impl fmt::Debug for Sealed { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Sealed").finish() + } +} + #[derive(Debug)] /// Boxed `Io` object with erased filter type pub struct IoBoxed(Io); diff --git a/ntex-io/src/tasks.rs b/ntex-io/src/tasks.rs index 4b80bdbc0..caab22e80 100644 --- a/ntex-io/src/tasks.rs +++ b/ntex-io/src/tasks.rs @@ -4,6 +4,7 @@ use ntex_bytes::{BytesVec, PoolRef}; use super::{io::Flags, IoRef, ReadStatus, WriteStatus}; +#[derive(Debug)] /// Context for io read task pub struct ReadContext(IoRef); @@ -97,6 +98,7 @@ impl ReadContext { } } +#[derive(Debug)] /// Context for io write task pub struct WriteContext(IoRef); diff --git a/ntex-io/src/types.rs b/ntex-io/src/types.rs index 31e6acff6..0153f5862 100644 --- a/ntex-io/src/types.rs +++ b/ntex-io/src/types.rs @@ -65,3 +65,13 @@ impl QueryItem { } } } + +impl fmt::Debug for QueryItem { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + if let Some(v) = self.as_ref() { + f.debug_tuple("QueryItem").field(v).finish() + } else { + f.debug_tuple("QueryItem").field(&None::).finish() + } + } +} diff --git a/ntex-io/src/utils.rs b/ntex-io/src/utils.rs index 4b5c2654f..0149d3db8 100644 --- a/ntex-io/src/utils.rs +++ b/ntex-io/src/utils.rs @@ -1,4 +1,4 @@ -use std::marker::PhantomData; +use std::{fmt, marker::PhantomData}; use ntex_service::{chain_factory, fn_service, Service, ServiceCtx, ServiceFactory}; use ntex_util::future::Ready; @@ -41,6 +41,14 @@ pub struct FilterServiceFactory { _t: PhantomData, } +impl + fmt::Debug, F> fmt::Debug for FilterServiceFactory { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("FilterServiceFactory") + .field("filter_factory", &self.filter) + .finish() + } +} + impl ServiceFactory> for FilterServiceFactory where T: FilterFactory + Clone, @@ -65,6 +73,14 @@ pub struct FilterService { _t: PhantomData, } +impl + fmt::Debug, F> fmt::Debug for FilterService { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("FilterService") + .field("filter_factory", &self.filter) + .finish() + } +} + impl Service> for FilterService where T: FilterFactory + Clone, diff --git a/ntex-tls/CHANGES.md b/ntex-tls/CHANGES.md index b96d57647..2f643bc83 100644 --- a/ntex-tls/CHANGES.md +++ b/ntex-tls/CHANGES.md @@ -1,5 +1,9 @@ # Changes +## [0.3.1] - 2023-09-11 + +* Add missing fmt::Debug impls + ## [0.3.0] - 2023-06-22 * Release v0.3.0 diff --git a/ntex-tls/Cargo.toml b/ntex-tls/Cargo.toml index a79052023..b2ec41a91 100644 --- a/ntex-tls/Cargo.toml +++ b/ntex-tls/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ntex-tls" -version = "0.3.0" +version = "0.3.1" authors = ["ntex contributors "] description = "An implementation of SSL streams for ntex backed by OpenSSL" keywords = ["network", "framework", "async", "futures"] @@ -26,9 +26,9 @@ rustls = ["tls_rust"] [dependencies] ntex-bytes = "0.1.19" -ntex-io = "0.3.0" -ntex-util = "0.3.0" -ntex-service = "1.2.0" +ntex-io = "0.3.3" +ntex-util = "0.3.2" +ntex-service = "1.2.6" log = "0.4" pin-project-lite = "0.2" diff --git a/ntex-tls/src/counter.rs b/ntex-tls/src/counter.rs index a82f2ff16..f2127db6d 100644 --- a/ntex-tls/src/counter.rs +++ b/ntex-tls/src/counter.rs @@ -3,12 +3,13 @@ use std::{cell::Cell, rc::Rc, task}; use ntex_util::task::LocalWaker; -#[derive(Clone)] +#[derive(Debug, Clone)] /// Simple counter with ability to notify task on reaching specific number /// /// Counter could be cloned, total count is shared across all clones. pub(super) struct Counter(Rc); +#[derive(Debug)] struct CounterInner { count: Cell, capacity: usize, @@ -17,7 +18,7 @@ struct CounterInner { impl Counter { /// Create `Counter` instance and set max value. - pub fn new(capacity: usize) -> Self { + pub(super) fn new(capacity: usize) -> Self { Counter(Rc::new(CounterInner { capacity, count: Cell::new(0), @@ -26,13 +27,13 @@ impl Counter { } /// Get counter guard. - pub fn get(&self) -> CounterGuard { + pub(super) fn get(&self) -> CounterGuard { CounterGuard::new(self.0.clone()) } /// Check if counter is not at capacity. If counter at capacity /// it registers notification for current task. - pub fn available(&self, cx: &mut task::Context<'_>) -> bool { + pub(super) fn available(&self, cx: &mut task::Context<'_>) -> bool { self.0.available(cx) } } diff --git a/ntex-tls/src/lib.rs b/ntex-tls/src/lib.rs index 201007280..13c61e0f7 100644 --- a/ntex-tls/src/lib.rs +++ b/ntex-tls/src/lib.rs @@ -1,4 +1,6 @@ //! An implementations of SSL streams for ntex ecosystem +#![deny(rust_2018_idioms, unreachable_pub, missing_debug_implementations)] + use std::sync::atomic::{AtomicUsize, Ordering}; #[doc(hidden)] diff --git a/ntex-tls/src/openssl/accept.rs b/ntex-tls/src/openssl/accept.rs index fd68aff32..d34f7201f 100644 --- a/ntex-tls/src/openssl/accept.rs +++ b/ntex-tls/src/openssl/accept.rs @@ -11,6 +11,7 @@ use crate::MAX_SSL_ACCEPT_COUNTER; use super::{SslAcceptor as IoSslAcceptor, SslFilter}; +#[derive(Debug)] /// Support `TLS` server connections via openssl package /// /// `openssl` feature enables `Acceptor` type @@ -71,6 +72,7 @@ impl ServiceFactory, C> for Acceptor { } } +#[derive(Debug)] /// Support `TLS` server connections via openssl package /// /// `openssl` feature enables `Acceptor` type diff --git a/ntex-tls/src/openssl/mod.rs b/ntex-tls/src/openssl/mod.rs index 93ab73d3a..b9dbf1abf 100644 --- a/ntex-tls/src/openssl/mod.rs +++ b/ntex-tls/src/openssl/mod.rs @@ -1,6 +1,6 @@ //! An implementation of SSL streams for ntex backed by OpenSSL use std::cell::{Cell, RefCell}; -use std::{any, cmp, error::Error, io, task::Context, task::Poll}; +use std::{any, cmp, error::Error, fmt, io, task::Context, task::Poll}; use ntex_bytes::{BufMut, BytesVec}; use ntex_io::{types, Filter, FilterFactory, FilterLayer, Io, Layer, ReadBuf, WriteBuf}; @@ -22,11 +22,13 @@ pub struct PeerCert(pub X509); pub struct PeerCertChain(pub Vec); /// An implementation of SSL streams +#[derive(Debug)] pub struct SslFilter { inner: RefCell>, handshake: Cell, } +#[derive(Debug)] struct IoInner { source: Option, destination: Option, @@ -242,6 +244,14 @@ impl Clone for SslAcceptor { } } +impl fmt::Debug for SslAcceptor { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("SslAcceptor") + .field("timeout", &self.timeout) + .finish() + } +} + impl FilterFactory for SslAcceptor { type Filter = SslFilter; @@ -292,6 +302,7 @@ impl FilterFactory for SslAcceptor { } } +#[derive(Debug)] pub struct SslConnector { ssl: ssl::Ssl, } diff --git a/ntex-tls/src/rustls/accept.rs b/ntex-tls/src/rustls/accept.rs index 3be86df4c..7e31a0da7 100644 --- a/ntex-tls/src/rustls/accept.rs +++ b/ntex-tls/src/rustls/accept.rs @@ -10,6 +10,7 @@ use ntex_util::{future::Ready, time::Millis}; use super::{TlsAcceptor, TlsFilter}; use crate::{counter::Counter, counter::CounterGuard, MAX_SSL_ACCEPT_COUNTER}; +#[derive(Debug)] /// Support `SSL` connections via rustls package /// /// `rust-tls` feature enables `RustlsAcceptor` type @@ -71,6 +72,7 @@ impl ServiceFactory, C> for Acceptor { } } +#[derive(Debug)] /// RusTLS based `Acceptor` service pub struct AcceptorService { acceptor: TlsAcceptor, diff --git a/ntex-tls/src/rustls/client.rs b/ntex-tls/src/rustls/client.rs index 9ec38e8a2..a00b3b42b 100644 --- a/ntex-tls/src/rustls/client.rs +++ b/ntex-tls/src/rustls/client.rs @@ -11,8 +11,9 @@ use crate::rustls::{IoInner, TlsFilter, Wrapper}; use super::{PeerCert, PeerCertChain}; +#[derive(Debug)] /// An implementation of SSL streams -pub struct TlsClientFilter { +pub(crate) struct TlsClientFilter { inner: IoInner, session: RefCell, } diff --git a/ntex-tls/src/rustls/mod.rs b/ntex-tls/src/rustls/mod.rs index 52bc75297..60880508f 100644 --- a/ntex-tls/src/rustls/mod.rs +++ b/ntex-tls/src/rustls/mod.rs @@ -25,11 +25,13 @@ pub struct PeerCert(pub Certificate); #[derive(Debug)] pub struct PeerCertChain(pub Vec); +#[derive(Debug)] /// An implementation of SSL streams pub struct TlsFilter { inner: InnerTlsFilter, } +#[derive(Debug)] enum InnerTlsFilter { Server(TlsServerFilter), Client(TlsClientFilter), @@ -110,6 +112,7 @@ impl FilterLayer for TlsFilter { } } +#[derive(Debug)] pub struct TlsAcceptor { cfg: Arc, timeout: Millis, @@ -162,6 +165,7 @@ impl FilterFactory for TlsAcceptor { } } +#[derive(Debug)] pub struct TlsConnector { cfg: Arc, } @@ -189,6 +193,7 @@ impl Clone for TlsConnector { } } +#[derive(Debug)] pub struct TlsConnectorConfigured { cfg: Arc, server_name: ServerName, @@ -217,6 +222,7 @@ impl FilterFactory for TlsConnectorConfigured { } } +#[derive(Debug)] pub(crate) struct IoInner { handshake: Cell, } diff --git a/ntex-tls/src/rustls/server.rs b/ntex-tls/src/rustls/server.rs index 2fa605749..c01437ad6 100644 --- a/ntex-tls/src/rustls/server.rs +++ b/ntex-tls/src/rustls/server.rs @@ -12,8 +12,9 @@ use crate::Servername; use super::{PeerCert, PeerCertChain}; +#[derive(Debug)] /// An implementation of SSL streams -pub struct TlsServerFilter { +pub(crate) struct TlsServerFilter { inner: IoInner, session: RefCell, } diff --git a/ntex-util/CHANGES.md b/ntex-util/CHANGES.md index 63f14bc14..3d80a5cb3 100644 --- a/ntex-util/CHANGES.md +++ b/ntex-util/CHANGES.md @@ -1,8 +1,12 @@ # Changes +## [0.3.2] - 2023-09-11 + +* Add missing fmt::Debug impls + ## [0.3.1] - 2023-06-24 -* Changed `BufferService` to maintain order +* Changed `BufferService` to maintain order * Buffer error type changed to indicate cancellation diff --git a/ntex-util/Cargo.toml b/ntex-util/Cargo.toml index 522f11440..bca66a1f4 100644 --- a/ntex-util/Cargo.toml +++ b/ntex-util/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ntex-util" -version = "0.3.1" +version = "0.3.2" authors = ["ntex contributors "] description = "Utilities for ntex framework" keywords = ["network", "framework", "async", "futures"] @@ -17,7 +17,7 @@ path = "src/lib.rs" [dependencies] ntex-rt = "0.4.7" -ntex-service = "1.2.2" +ntex-service = "1.2.6" bitflags = "1.3" fxhash = "0.2.1" log = "0.4" diff --git a/ntex-util/src/channel/cell.rs b/ntex-util/src/channel/cell.rs index 4e5ca39b9..d35e3dfb5 100644 --- a/ntex-util/src/channel/cell.rs +++ b/ntex-util/src/channel/cell.rs @@ -46,6 +46,7 @@ impl Cell { } } +#[derive(Debug)] pub(super) struct WeakCell { inner: Weak>, } diff --git a/ntex-util/src/channel/condition.rs b/ntex-util/src/channel/condition.rs index e6c615f8f..2e329734d 100644 --- a/ntex-util/src/channel/condition.rs +++ b/ntex-util/src/channel/condition.rs @@ -5,9 +5,10 @@ use super::cell::Cell; use crate::{future::poll_fn, task::LocalWaker}; /// Condition allows to notify multiple waiters at the same time -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct Condition(Cell); +#[derive(Debug)] struct Inner { data: Slab>, } @@ -50,6 +51,7 @@ impl Drop for Condition { } } +#[derive(Debug)] #[must_use = "Waiter do nothing unless polled"] pub struct Waiter { token: usize, diff --git a/ntex-util/src/channel/mpsc.rs b/ntex-util/src/channel/mpsc.rs index 442e8b439..dc311a444 100644 --- a/ntex-util/src/channel/mpsc.rs +++ b/ntex-util/src/channel/mpsc.rs @@ -124,6 +124,7 @@ impl Drop for Sender { } } +#[derive(Debug)] /// Weak sender type pub struct WeakSender { shared: WeakCell>, diff --git a/ntex-util/src/lib.rs b/ntex-util/src/lib.rs index f118e13d6..5fecad452 100644 --- a/ntex-util/src/lib.rs +++ b/ntex-util/src/lib.rs @@ -1,4 +1,6 @@ //! Utilities for ntex framework +#![deny(rust_2018_idioms, unreachable_pub, missing_debug_implementations)] + pub mod channel; pub mod future; pub mod services; diff --git a/ntex-util/src/services/buffer.rs b/ntex-util/src/services/buffer.rs index ce1dcb6b2..571d26b89 100644 --- a/ntex-util/src/services/buffer.rs +++ b/ntex-util/src/services/buffer.rs @@ -1,7 +1,7 @@ //! Service that buffers incomming requests. use std::cell::{Cell, RefCell}; use std::task::{ready, Context, Poll}; -use std::{collections::VecDeque, future::Future, marker::PhantomData, pin::Pin}; +use std::{collections::VecDeque, fmt, future::Future, marker::PhantomData, pin::Pin}; use ntex_service::{IntoService, Middleware, Service, ServiceCallToCall, ServiceCtx}; @@ -16,16 +16,6 @@ pub struct Buffer { _t: PhantomData, } -impl Default for Buffer { - fn default() -> Self { - Self { - buf_size: 16, - cancel_on_shutdown: false, - _t: PhantomData, - } - } -} - impl Buffer { pub fn buf_size(mut self, size: usize) -> Self { self.buf_size = size; @@ -41,6 +31,25 @@ impl Buffer { } } +impl Default for Buffer { + fn default() -> Self { + Self { + buf_size: 16, + cancel_on_shutdown: false, + _t: PhantomData, + } + } +} + +impl fmt::Debug for Buffer { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Buffer") + .field("buf_size", &self.buf_size) + .field("cancel_on_shutdown", &self.cancel_on_shutdown) + .finish() + } +} + impl Clone for Buffer { fn clone(&self) -> Self { Self { @@ -127,6 +136,22 @@ where } } +impl fmt::Debug for BufferService +where + S: Service + fmt::Debug, +{ + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("BufferService") + .field("size", &self.size) + .field("cancel_on_shutdown", &self.cancel_on_shutdown) + .field("ready", &self.ready) + .field("service", &self.service) + .field("buf", &self.buf) + .field("next_call", &self.next_call) + .finish() + } +} + impl Service for BufferService where S: Service, diff --git a/ntex-util/src/services/counter.rs b/ntex-util/src/services/counter.rs index a16987eda..3a2484178 100644 --- a/ntex-util/src/services/counter.rs +++ b/ntex-util/src/services/counter.rs @@ -5,8 +5,10 @@ use crate::task::LocalWaker; /// Simple counter with ability to notify task on reaching specific number /// /// Counter could be cloned, total count is shared across all clones. +#[derive(Debug)] pub struct Counter(Rc); +#[derive(Debug)] struct CounterInner { count: Cell, capacity: usize, @@ -40,6 +42,7 @@ impl Counter { } } +#[derive(Debug)] pub struct CounterGuard(Rc); impl CounterGuard { diff --git a/ntex-util/src/services/inflight.rs b/ntex-util/src/services/inflight.rs index eb15e20b4..8fc6754c7 100644 --- a/ntex-util/src/services/inflight.rs +++ b/ntex-util/src/services/inflight.rs @@ -37,6 +37,7 @@ impl Middleware for InFlight { } } +#[derive(Debug)] pub struct InFlightService { count: Counter, service: S, diff --git a/ntex-util/src/services/keepalive.rs b/ntex-util/src/services/keepalive.rs index 93fb7505d..b80dde753 100644 --- a/ntex-util/src/services/keepalive.rs +++ b/ntex-util/src/services/keepalive.rs @@ -1,5 +1,5 @@ use std::task::{Context, Poll}; -use std::{cell::Cell, convert::Infallible, marker, time::Duration, time::Instant}; +use std::{cell::Cell, convert::Infallible, fmt, marker, time::Duration, time::Instant}; use ntex_service::{Service, ServiceCtx, ServiceFactory}; @@ -45,6 +45,15 @@ where } } +impl fmt::Debug for KeepAlive { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("KeepAlive") + .field("ka", &self.ka) + .field("f", &std::any::type_name::()) + .finish() + } +} + impl ServiceFactory for KeepAlive where F: Fn() -> E + Clone, @@ -86,6 +95,16 @@ where } } +impl fmt::Debug for KeepAliveService { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("KeepAliveService") + .field("dur", &self.dur) + .field("expire", &self.expire) + .field("f", &std::any::type_name::()) + .finish() + } +} + impl Service for KeepAliveService where F: Fn() -> E, diff --git a/ntex-util/src/services/onerequest.rs b/ntex-util/src/services/onerequest.rs index dde7b3cc2..5d78f8481 100644 --- a/ntex-util/src/services/onerequest.rs +++ b/ntex-util/src/services/onerequest.rs @@ -22,6 +22,7 @@ impl Middleware for OneRequest { } } +#[derive(Clone, Debug)] pub struct OneRequestService { waker: LocalWaker, service: S, diff --git a/ntex-util/src/services/variant.rs b/ntex-util/src/services/variant.rs index 647abb3b7..f30672df3 100644 --- a/ntex-util/src/services/variant.rs +++ b/ntex-util/src/services/variant.rs @@ -1,5 +1,5 @@ //! Contains `Variant` service and related types and functions. -use std::{future::Future, marker::PhantomData, pin::Pin, task::Context, task::Poll}; +use std::{fmt, future::Future, marker::PhantomData, pin::Pin, task::Context, task::Poll}; use ntex_service::{IntoServiceFactory, Service, ServiceCall, ServiceCtx, ServiceFactory}; @@ -46,6 +46,17 @@ where } } +impl fmt::Debug for Variant +where + A: fmt::Debug, +{ + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Variant") + .field("V1", &self.factory) + .finish() + } +} + macro_rules! variant_impl_and ({$fac1_type:ident, $fac2_type:ident, $name:ident, $r_name:ident, $m_name:ident, ($($T:ident),+), ($($R:ident),+)} => { #[allow(non_snake_case)] @@ -73,7 +84,7 @@ macro_rules! variant_impl_and ({$fac1_type:ident, $fac2_type:ident, $name:ident, macro_rules! variant_impl ({$mod_name:ident, $enum_type:ident, $srv_type:ident, $fac_type:ident, $(($n:tt, $T:ident, $R:ident)),+} => { - #[allow(non_snake_case)] + #[allow(non_snake_case, missing_debug_implementations)] pub enum $enum_type { V1(V1R), $($T($R),)+ @@ -96,6 +107,15 @@ macro_rules! variant_impl ({$mod_name:ident, $enum_type:ident, $srv_type:ident, } } + impl fmt::Debug for $srv_type { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct(stringify!($srv_type)) + .field("V1", &self.V1) + $(.field(stringify!($T), &self.$T))+ + .finish() + } + } + impl Service<$enum_type> for $srv_type where V1: Service, @@ -154,6 +174,15 @@ macro_rules! variant_impl ({$mod_name:ident, $enum_type:ident, $srv_type:ident, } } + impl fmt::Debug for $fac_type { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct(stringify!(fac_type)) + .field("V1", &self.V1) + $(.field(stringify!($T), &self.$T))+ + .finish() + } + } + impl ServiceFactory<$enum_type, V1C> for $fac_type where V1: ServiceFactory, diff --git a/ntex-util/src/task.rs b/ntex-util/src/task.rs index a17432608..d9e0d1042 100644 --- a/ntex-util/src/task.rs +++ b/ntex-util/src/task.rs @@ -58,6 +58,12 @@ impl LocalWaker { } } +impl Clone for LocalWaker { + fn clone(&self) -> Self { + LocalWaker::new() + } +} + impl fmt::Debug for LocalWaker { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "LocalWaker") diff --git a/ntex/CHANGES.md b/ntex/CHANGES.md index 7c7ea4164..e1e45858c 100644 --- a/ntex/CHANGES.md +++ b/ntex/CHANGES.md @@ -1,5 +1,9 @@ # Changes +## [0.7.4] - 2023-09-11 + +* Add missing fmt::Debug impls + ## [0.7.3] - 2023-08-10 * Update ntex-service diff --git a/ntex/Cargo.toml b/ntex/Cargo.toml index f4a213a90..8e5034cbf 100644 --- a/ntex/Cargo.toml +++ b/ntex/Cargo.toml @@ -49,16 +49,16 @@ async-std = ["ntex-rt/async-std", "ntex-async-std", "ntex-connect/async-std"] [dependencies] ntex-codec = "0.6.2" -ntex-connect = "0.3.0" +ntex-connect = "0.3.1" ntex-http = "0.1.9" ntex-router = "0.5.1" -ntex-service = "1.2.5" +ntex-service = "1.2.6" ntex-macros = "0.1.3" -ntex-util = "0.3.0" +ntex-util = "0.3.2" ntex-bytes = "0.1.19" ntex-h2 = "0.3.2" ntex-rt = "0.4.9" -ntex-io = "0.3.2" +ntex-io = "0.3.3" ntex-tls = "0.3.0" ntex-tokio = { version = "0.3.0", optional = true } ntex-glommio = { version = "0.3.0", optional = true } diff --git a/ntex/src/http/client/builder.rs b/ntex/src/http/client/builder.rs index d16429de5..ee905b34e 100644 --- a/ntex/src/http/client/builder.rs +++ b/ntex/src/http/client/builder.rs @@ -14,6 +14,7 @@ use super::{Client, ClientConfig, Connect, Connection, Connector}; /// /// This type can be used to construct an instance of `Client` through a /// builder-like pattern. +#[derive(Debug)] pub struct ClientBuilder { config: ClientConfig, default_headers: bool, @@ -44,7 +45,9 @@ impl ClientBuilder { /// Use custom connector service. pub fn connector(mut self, connector: T) -> Self where - T: Service + 'static, + T: Service + + fmt::Debug + + 'static, { self.config.connector = Box::new(ConnectorWrapper(connector.into())); self diff --git a/ntex/src/http/client/connect.rs b/ntex/src/http/client/connect.rs index dde1a0a44..c7182a42b 100644 --- a/ntex/src/http/client/connect.rs +++ b/ntex/src/http/client/connect.rs @@ -1,4 +1,4 @@ -use std::net; +use std::{fmt, net}; use crate::http::{body::Body, RequestHeadType}; use crate::{service::Pipeline, service::Service, util::BoxFuture}; @@ -7,9 +7,21 @@ use super::error::{ConnectError, SendRequestError}; use super::response::ClientResponse; use super::{Connect as ClientConnect, Connection}; +// #[derive(Debug)] pub(super) struct ConnectorWrapper(pub(crate) Pipeline); -pub(super) trait Connect { +impl fmt::Debug for ConnectorWrapper +where + T: fmt::Debug, +{ + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Connector") + .field("service", &self.0) + .finish() + } +} + +pub(super) trait Connect: fmt::Debug { fn send_request( &self, head: RequestHeadType, @@ -20,7 +32,7 @@ pub(super) trait Connect { impl Connect for ConnectorWrapper where - T: Service, + T: Service + fmt::Debug, { fn send_request( &self, diff --git a/ntex/src/http/client/connector.rs b/ntex/src/http/client/connector.rs index daf74c993..294abf363 100644 --- a/ntex/src/http/client/connector.rs +++ b/ntex/src/http/client/connector.rs @@ -1,4 +1,4 @@ -use std::{task::Context, task::Poll, time::Duration}; +use std::{fmt, task::Context, task::Poll, time::Duration}; use ntex_h2::{self as h2}; @@ -18,6 +18,7 @@ use crate::connect::rustls::ClientConfig; type BoxedConnector = boxed::BoxService, IoBoxed, ConnectError>; +#[derive(Debug)] /// Manages http client network connectivity. /// /// The `Connector` type uses a builder-like combinator pattern for service @@ -222,7 +223,8 @@ impl Connector { /// its combinator chain. pub fn finish( self, - ) -> impl Service { + ) -> impl Service + fmt::Debug + { let tcp_service = connector(self.connector, self.timeout, self.disconnect_timeout); let ssl_pool = if let Some(ssl_connector) = self.ssl_connector { @@ -257,7 +259,7 @@ fn connector( connector: BoxedConnector, timeout: Millis, disconnect_timeout: Millis, -) -> impl Service { +) -> impl Service + fmt::Debug { TimeoutService::new( timeout, apply_fn(connector, |msg: Connect, srv| { @@ -278,6 +280,7 @@ fn connector( }) } +#[derive(Debug)] struct InnerConnector { tcp_pool: ConnectionPool, ssl_pool: Option>, diff --git a/ntex/src/http/client/mod.rs b/ntex/src/http/client/mod.rs index 89e9d9470..9d2f08679 100644 --- a/ntex/src/http/client/mod.rs +++ b/ntex/src/http/client/mod.rs @@ -47,7 +47,7 @@ use crate::time::Millis; use self::connect::{Connect as HttpConnect, ConnectorWrapper}; -#[derive(Clone)] +#[derive(Debug, Clone)] pub struct Connect { pub uri: Uri, pub addr: Option, @@ -70,9 +70,10 @@ pub struct Connect { /// println!("Response: {:?}", res); /// } /// ``` -#[derive(Clone)] +#[derive(Debug, Clone)] pub struct Client(Rc); +#[derive(Debug)] struct ClientConfig { pub(self) connector: Box, pub(self) headers: HeaderMap, diff --git a/ntex/src/http/client/pool.rs b/ntex/src/http/client/pool.rs index 6fd505559..287a3c8ce 100644 --- a/ntex/src/http/client/pool.rs +++ b/ntex/src/http/client/pool.rs @@ -43,6 +43,7 @@ struct AvailableConnection { } /// Connections pool +#[derive(Debug)] pub(super) struct ConnectionPool { connector: Pipeline, inner: Rc>, @@ -174,6 +175,7 @@ where } } +#[derive(Debug)] pub(super) struct Inner { conn_lifetime: Duration, conn_keep_alive: Duration, @@ -187,6 +189,7 @@ pub(super) struct Inner { waiters: Rc>, } +#[derive(Debug)] struct Waiters { waiters: HashMap>, pool: pool::Pool>, diff --git a/ntex/src/lib.rs b/ntex/src/lib.rs index a6aa6ced5..bc784c8d0 100644 --- a/ntex/src/lib.rs +++ b/ntex/src/lib.rs @@ -9,7 +9,7 @@ #![warn( rust_2018_idioms, unreachable_pub, - // missing_debug_implementations, + missing_debug_implementations, // missing_docs, )] #![allow( diff --git a/ntex/src/web/types/json.rs b/ntex/src/web/types/json.rs index b83172ae2..feb2acc55 100644 --- a/ntex/src/web/types/json.rs +++ b/ntex/src/web/types/json.rs @@ -253,6 +253,21 @@ impl Default for JsonConfig { } } +impl fmt::Debug for JsonConfig { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("JsonConfig") + .field("limit", &self.limit) + .field( + "content_type", + &self + .content_type + .as_ref() + .map(|_| "Arc bool + Send + Sync>"), + ) + .finish() + } +} + /// Request's payload json parser, it resolves to a deserialized `T` value. /// /// Returns error: diff --git a/ntex/src/ws/sink.rs b/ntex/src/ws/sink.rs index 7744662b9..ba78f5e24 100644 --- a/ntex/src/ws/sink.rs +++ b/ntex/src/ws/sink.rs @@ -3,9 +3,10 @@ use std::{future::Future, rc::Rc}; use crate::io::{IoRef, OnDisconnect}; use crate::ws; -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct WsSink(Rc); +#[derive(Debug)] struct WsSinkInner { io: IoRef, codec: ws::Codec, diff --git a/ntex/src/ws/transport.rs b/ntex/src/ws/transport.rs index e379ee22f..e594320b7 100644 --- a/ntex/src/ws/transport.rs +++ b/ntex/src/ws/transport.rs @@ -15,6 +15,7 @@ bitflags::bitflags! { } } +#[derive(Clone, Debug)] /// An implementation of WebSockets streams pub struct WsTransport { pool: PoolRef, @@ -171,6 +172,7 @@ impl FilterLayer for WsTransport { } } +#[derive(Clone, Debug)] /// WebSockets transport factory pub struct WsTransportFactory { codec: Codec,