mirror of
https://github.com/ntex-rs/ntex.git
synced 2025-04-03 21:07:39 +03:00
Add missing fmt::Debug impls
This commit is contained in:
parent
02e111d373
commit
27f07b6fc4
9 changed files with 94 additions and 10 deletions
|
@ -53,7 +53,7 @@ pub enum WriteStatus {
|
|||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
pub trait FilterLayer: 'static {
|
||||
pub trait FilterLayer: fmt::Debug + 'static {
|
||||
/// Create buffers for this filter
|
||||
const BUFFERS: bool = true;
|
||||
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
# Changes
|
||||
|
||||
## [0.5.2] - 2023-09-12
|
||||
|
||||
* Add missing fmt::Debug impls
|
||||
|
||||
## [0.5.1] - 2021-08-23
|
||||
|
||||
* Fix: segments could be lost in case of immediate match
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "ntex-router"
|
||||
version = "0.5.1"
|
||||
version = "0.5.2"
|
||||
authors = ["ntex contributors <team@ntex.rs>"]
|
||||
description = "Path router"
|
||||
keywords = ["ntex"]
|
||||
|
@ -18,10 +18,10 @@ default = ["http"]
|
|||
|
||||
[dependencies]
|
||||
serde = "1.0"
|
||||
ntex-bytes = "0.1.9"
|
||||
ntex-bytes = "0.1.19"
|
||||
log = "0.4"
|
||||
http = { version = "0.2", optional = true }
|
||||
regex = { version = "1.7.0", default-features = false, features = ["std"] }
|
||||
regex = { version = "1.9.5", default-features = false, features = ["std"] }
|
||||
|
||||
[dev-dependencies]
|
||||
http = "0.2"
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
use serde::de::{self, Deserializer, Error as DeError, Visitor};
|
||||
use serde::forward_to_deserialize_any;
|
||||
|
||||
use crate::path::{Path, PathIter};
|
||||
use crate::ResourcePath;
|
||||
use crate::{path::Path, path::PathIter, ResourcePath};
|
||||
|
||||
macro_rules! unsupported_type {
|
||||
($trait_fn:ident, $name:expr) => {
|
||||
|
@ -42,6 +41,7 @@ macro_rules! parse_single_value {
|
|||
};
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct PathDeserializer<'de, T: ResourcePath> {
|
||||
path: &'de Path<T>,
|
||||
}
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
#![deny(rust_2018_idioms, unreachable_pub)]
|
||||
#![deny(
|
||||
rust_2018_idioms,
|
||||
warnings,
|
||||
unreachable_pub,
|
||||
missing_debug_implementations
|
||||
)]
|
||||
#![warn(nonstandard_style, future_incompatible)]
|
||||
|
||||
//! Resource path matching library.
|
||||
|
@ -14,6 +19,7 @@ pub use self::resource::ResourceDef;
|
|||
pub use self::router::{ResourceId, Router, RouterBuilder};
|
||||
|
||||
#[doc(hidden)]
|
||||
#[derive(Debug)]
|
||||
pub struct ResourceInfo;
|
||||
|
||||
pub trait Resource<T: ResourcePath> {
|
||||
|
|
|
@ -5,7 +5,7 @@ use super::{IntoPattern, Resource, ResourceDef, ResourcePath};
|
|||
pub struct ResourceId(u16);
|
||||
|
||||
/// Resource router.
|
||||
#[derive(Clone)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Router<T, U = ()> {
|
||||
tree: Tree,
|
||||
resources: Vec<(ResourceDef, T, Option<U>)>,
|
||||
|
@ -111,6 +111,7 @@ impl<T, U> Router<T, U> {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct RouterBuilder<T, U = ()> {
|
||||
insensitive: bool,
|
||||
resources: Vec<(ResourceDef, T, Option<U>)>,
|
||||
|
|
|
@ -51,7 +51,7 @@ async-std = ["ntex-rt/async-std", "ntex-async-std", "ntex-connect/async-std"]
|
|||
ntex-codec = "0.6.2"
|
||||
ntex-connect = "0.3.1"
|
||||
ntex-http = "0.1.10"
|
||||
ntex-router = "0.5.1"
|
||||
ntex-router = "0.5.2"
|
||||
ntex-service = "1.2.6"
|
||||
ntex-macros = "0.1.3"
|
||||
ntex-util = "0.3.2"
|
||||
|
|
|
@ -269,6 +269,15 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<S> From<BoxedBodyStream<S>> for Body
|
||||
where
|
||||
S: Stream<Item = Result<Bytes, Box<dyn Error>>> + Unpin + 'static,
|
||||
{
|
||||
fn from(s: BoxedBodyStream<S>) -> Body {
|
||||
Body::from_message(s)
|
||||
}
|
||||
}
|
||||
|
||||
impl MessageBody for Bytes {
|
||||
fn size(&self) -> BodySize {
|
||||
BodySize::Sized(self.len() as u64)
|
||||
|
@ -372,6 +381,7 @@ impl MessageBody for String {
|
|||
}
|
||||
|
||||
/// Type represent streaming body.
|
||||
///
|
||||
/// Response does not contain `content-length` header and appropriate transfer encoding is used.
|
||||
pub struct BodyStream<S, E> {
|
||||
stream: S,
|
||||
|
@ -391,6 +401,15 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<S, E> fmt::Debug for BodyStream<S, E> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("BodyStream")
|
||||
.field("stream", &std::any::type_name::<S>())
|
||||
.field("error", &std::any::type_name::<E>())
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl<S, E> MessageBody for BodyStream<S, E>
|
||||
where
|
||||
S: Stream<Item = Result<Bytes, E>> + Unpin + 'static,
|
||||
|
@ -434,6 +453,14 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<S> fmt::Debug for BoxedBodyStream<S> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("BoxedBodyStream")
|
||||
.field("stream", &std::any::type_name::<S>())
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl<S> MessageBody for BoxedBodyStream<S>
|
||||
where
|
||||
S: Stream<Item = Result<Bytes, Box<dyn Error>>> + Unpin + 'static,
|
||||
|
@ -477,6 +504,15 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<S> fmt::Debug for SizedStream<S> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("SizedStream")
|
||||
.field("size", &self.size)
|
||||
.field("stream", &std::any::type_name::<S>())
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl<S> MessageBody for SizedStream<S>
|
||||
where
|
||||
S: Stream<Item = Result<Bytes, Box<dyn Error>>> + Unpin + 'static,
|
||||
|
@ -695,6 +731,21 @@ mod tests {
|
|||
#[crate::rt_test]
|
||||
async fn body_stream() {
|
||||
let st = BodyStream::new(stream::once(Ready::<_, io::Error>::Ok(Bytes::from("1"))));
|
||||
assert!(format!("{:?}", st).contains("BodyStream"));
|
||||
let body: Body = st.into();
|
||||
assert!(format!("{:?}", body).contains("Body::Message(_)"));
|
||||
assert!(body != Body::None);
|
||||
|
||||
let res = ResponseBody::new(body);
|
||||
assert!(res.as_ref().is_some());
|
||||
}
|
||||
|
||||
#[crate::rt_test]
|
||||
async fn boxed_body_stream() {
|
||||
let st = BoxedBodyStream::new(stream::once(Ready::<_, Box<dyn Error>>::Ok(
|
||||
Bytes::from("1"),
|
||||
)));
|
||||
assert!(format!("{:?}", st).contains("BoxedBodyStream"));
|
||||
let body: Body = st.into();
|
||||
assert!(format!("{:?}", body).contains("Body::Message(_)"));
|
||||
assert!(body != Body::None);
|
||||
|
@ -726,6 +777,7 @@ mod tests {
|
|||
2,
|
||||
stream::iter(["1", "", "2"].iter().map(|&v| Ok(Bytes::from(v)))),
|
||||
);
|
||||
assert!(format!("{:?}", body).contains("SizedStream"));
|
||||
assert_eq!(
|
||||
poll_fn(|cx| body.poll_next_chunk(cx)).await.unwrap().ok(),
|
||||
Some(Bytes::from("1")),
|
||||
|
|
|
@ -41,8 +41,10 @@ impl Config {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ServiceConfig(pub(super) Rc<RefCell<ServiceConfigInner>>);
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(super) struct ServiceConfigInner {
|
||||
pub(super) services: Vec<(String, net::TcpListener)>,
|
||||
pub(super) apply: Option<Box<dyn ServiceRuntimeConfiguration + Send>>,
|
||||
|
@ -207,7 +209,7 @@ impl InternalServiceFactory for ConfiguredService {
|
|||
}
|
||||
}
|
||||
|
||||
pub(super) trait ServiceRuntimeConfiguration {
|
||||
pub(super) trait ServiceRuntimeConfiguration: fmt::Debug {
|
||||
fn clone(&self) -> Box<dyn ServiceRuntimeConfiguration + Send>;
|
||||
|
||||
fn configure(&self, rt: ServiceRuntime) -> BoxFuture<'static, Result<(), ()>>;
|
||||
|
@ -221,6 +223,14 @@ pub(super) struct ConfigWrapper<F, R, E> {
|
|||
// SAFETY: we dont store R or E in ConfigWrapper
|
||||
unsafe impl<F: Send, R, E> Send for ConfigWrapper<F, R, E> {}
|
||||
|
||||
impl<F, R, E> fmt::Debug for ConfigWrapper<F, R, E> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("ConfigWrapper")
|
||||
.field("f", &std::any::type_name::<F>())
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl<F, R, E> ServiceRuntimeConfiguration for ConfigWrapper<F, R, E>
|
||||
where
|
||||
F: Fn(ServiceRuntime) -> R + Send + Clone + 'static,
|
||||
|
@ -256,6 +266,17 @@ struct ServiceRuntimeInner {
|
|||
onstart: Vec<BoxFuture<'static, ()>>,
|
||||
}
|
||||
|
||||
impl fmt::Debug for ServiceRuntime {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let inner = self.0.borrow();
|
||||
f.debug_struct("ServiceRuntimer")
|
||||
.field("names", &inner.names)
|
||||
.field("services", &inner.services)
|
||||
.field("onstart", &inner.onstart.len())
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl ServiceRuntime {
|
||||
fn new(names: HashMap<String, Token>) -> Self {
|
||||
ServiceRuntime(Rc::new(RefCell::new(ServiceRuntimeInner {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue