Skip to content

Commit

Permalink
Add missing fmt::Debug impls (#224)
Browse files Browse the repository at this point in the history
* Add missing fmt::Debug impls
  • Loading branch information
fafhrd91 authored Sep 11, 2023
1 parent 19cc8ab commit 02e111d
Show file tree
Hide file tree
Showing 96 changed files with 855 additions and 198 deletions.
4 changes: 4 additions & 0 deletions ntex-connect/CHANGES.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 6 additions & 6 deletions ntex-connect/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ntex-connect"
version = "0.3.0"
version = "0.3.1"
authors = ["ntex contributors <team@ntex.rs>"]
description = "ntexwork connect utils for ntex framework"
keywords = ["network", "framework", "async", "futures"]
Expand Down Expand Up @@ -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-http = "0.1.10"
ntex-io = "0.3.3"
ntex-rt = "0.4.7"
ntex-tls = "0.3.0"
ntex-util = "0.3.0"
ntex-tls = "0.3.1"
ntex-util = "0.3.2"
log = "0.4"
thiserror = "1.0"

Expand Down
2 changes: 2 additions & 0 deletions ntex-connect/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//! Tcp connector service
#![deny(rust_2018_idioms, unreachable_pub, missing_debug_implementations)]

#[macro_use]
extern crate log;

Expand Down
11 changes: 10 additions & 1 deletion ntex-connect/src/openssl.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -88,6 +88,15 @@ impl<T> Clone for Connector<T> {
}
}

impl<T> fmt::Debug for Connector<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Connector(openssl)")
.field("connector", &self.connector)
.field("openssl", &self.openssl)
.finish()
}
}

impl<T: Address, C: 'static> ServiceFactory<Connect<T>, C> for Connector<T> {
type Response = Io<Layer<SslFilter>>;
type Error = ConnectError;
Expand Down
10 changes: 9 additions & 1 deletion ntex-connect/src/rustls.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::io;
use std::{fmt, io};

pub use ntex_tls::rustls::TlsFilter;
pub use tls_rustls::{ClientConfig, ServerName};
Expand Down Expand Up @@ -92,6 +92,14 @@ impl<T> Clone for Connector<T> {
}
}

impl<T> fmt::Debug for Connector<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Connector(rustls)")
.field("connector", &self.connector)
.finish()
}
}

impl<T: Address, C: 'static> ServiceFactory<Connect<T>, C> for Connector<T> {
type Response = Io<Layer<TlsFilter>>;
type Error = ConnectError;
Expand Down
19 changes: 18 additions & 1 deletion ntex-connect/src/service.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -61,6 +61,15 @@ impl<T> Clone for Connector<T> {
}
}

impl<T> fmt::Debug for Connector<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Connector")
.field("resolver", &self.resolver)
.field("memory_pool", &self.pool)
.finish()
}
}

impl<T: Address, C: 'static> ServiceFactory<Connect<T>, C> for Connector<T> {
type Response = Io;
type Error = ConnectError;
Expand Down Expand Up @@ -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<Io, ConnectError>;

Expand Down
4 changes: 4 additions & 0 deletions ntex-http/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changes

## [0.1.10] - 2023-09-11

* Add missing fmt::Debug impls

## [0.1.9] - 2022-12-09

* Add helper method HeaderValue::as_shared()
Expand Down
4 changes: 2 additions & 2 deletions ntex-http/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ntex-http"
version = "0.1.9"
version = "0.1.10"
authors = ["ntex contributors <team@ntex.rs>"]
description = "Http types for ntex framework"
keywords = ["network", "framework", "async", "futures"]
Expand All @@ -20,4 +20,4 @@ http = "0.2"
log = "0.4"
fxhash = "0.2.1"
itoa = "1.0.4"
ntex-bytes = "0.1.17"
ntex-bytes = "0.1.19"
2 changes: 1 addition & 1 deletion ntex-http/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ enum ErrorKind {
}

impl fmt::Debug for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_tuple("ntex_http::Error")
// Skip the noise of the ErrorKind enum
.field(&self.get_ref())
Expand Down
2 changes: 2 additions & 0 deletions ntex-http/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//! Http protocol support.
#![deny(rust_2018_idioms, unreachable_pub, missing_debug_implementations)]

pub mod error;
mod map;
mod value;
Expand Down
4 changes: 4 additions & 0 deletions ntex-http/src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ impl Value {
}
}

#[derive(Debug)]
pub struct ValueIntoIter {
value: Value,
}
Expand Down Expand Up @@ -444,6 +445,7 @@ impl TryFrom<&str> for Value {
}
}

#[derive(Debug)]
pub struct GetAll<'a> {
idx: usize,
item: Option<&'a Value>,
Expand Down Expand Up @@ -477,6 +479,7 @@ impl<'a> Iterator for GetAll<'a> {
}
}

#[derive(Debug)]
pub struct Keys<'a>(hash_map::Keys<'a, HeaderName, Value>);

impl<'a> Iterator for Keys<'a> {
Expand All @@ -497,6 +500,7 @@ impl<'a> IntoIterator for &'a HeaderMap {
}
}

#[derive(Debug)]
pub struct Iter<'a> {
idx: usize,
current: Option<(&'a HeaderName, &'a VecDeque<HeaderValue>)>,
Expand Down
2 changes: 1 addition & 1 deletion ntex-http/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ fn is_valid(b: u8) -> bool {
impl Error for InvalidHeaderValue {}

impl fmt::Debug for InvalidHeaderValue {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("InvalidHeaderValue")
// skip _priv noise
.finish()
Expand Down
4 changes: 4 additions & 0 deletions ntex-io/CHANGES.md
Original file line number Diff line number Diff line change
@@ -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>`
Expand Down
6 changes: 3 additions & 3 deletions ntex-io/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ntex-io"
version = "0.3.2"
version = "0.3.3"
authors = ["ntex contributors <team@ntex.rs>"]
description = "Utilities for encoding and decoding frames"
keywords = ["network", "framework", "async", "futures"]
Expand All @@ -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"
Expand Down
40 changes: 31 additions & 9 deletions ntex-io/src/buf.rs
Original file line number Diff line number Diff line change
@@ -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<Option<BytesVec>>, Cell<Option<BytesVec>>);
#[derive(Default)]
pub(crate) struct Buffer(Cell<Option<BytesVec>>, Cell<Option<BytesVec>>);

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<Buffer>>,
Expand All @@ -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)));
}
}
}
Expand All @@ -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());
Expand Down Expand Up @@ -265,6 +285,7 @@ impl Stack {
}
}

#[derive(Debug)]
pub struct ReadBuf<'a> {
pub(crate) io: &'a IoRef,
pub(crate) curr: &'a Buffer,
Expand Down Expand Up @@ -403,6 +424,7 @@ impl<'a> ReadBuf<'a> {
}
}

#[derive(Debug)]
pub struct WriteBuf<'a> {
pub(crate) io: &'a IoRef,
pub(crate) curr: &'a Buffer,
Expand Down
3 changes: 2 additions & 1 deletion ntex-io/src/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ where
pool: Pool,
}

pub struct DispatcherShared<S, U>
pub(crate) struct DispatcherShared<S, U>
where
S: Service<DispatchItem<U>, Response = Option<Response<U>>>,
U: Encoder + Decoder,
Expand All @@ -64,6 +64,7 @@ enum DispatcherState {
Shutdown,
}

#[derive(Debug)]
enum DispatcherError<S, U> {
Encoder(U),
Service(S),
Expand Down
2 changes: 2 additions & 0 deletions ntex-io/src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -11,6 +12,7 @@ impl Base {
}
}

#[derive(Debug)]
pub struct Layer<F, L = Base>(pub(crate) F, L);

impl<F: FilterLayer, L: Filter> Layer<F, L> {
Expand Down
Loading

0 comments on commit 02e111d

Please sign in to comment.