diff --git a/hyper/src/service/make.rs b/hyper/src/service/make.rs index e973e89..3f4f369 100644 --- a/hyper/src/service/make.rs +++ b/hyper/src/service/make.rs @@ -27,16 +27,12 @@ where loop {} } } -pub trait MakeServiceRef: self::sealed::Sealed<(Target, ReqBody)> { - type ResBody: HttpBody; - type Error: Into>; +pub trait MakeServiceRef { + type ResBody; + type Error; type Service: HttpService; - type MakeError: Into>; - type Future: Future>; - type __DontNameMe: self::sealed::CantImpl; - fn poll_ready_ref(&mut self, cx: &mut task::Context<'_>) -> Poll>; - fn make_service_ref(&mut self, target: &Target) -> Self::Future; } + impl MakeServiceRef for T where T: for<'a> Service<&'a Target, Error = ME, Response = S, Future = F>, @@ -50,15 +46,6 @@ where type Error = E; type Service = S; type ResBody = OB; - type MakeError = ME; - type Future = F; - type __DontNameMe = self::sealed::CantName; - fn poll_ready_ref(&mut self, cx: &mut task::Context<'_>) -> Poll> { - loop {} - } - fn make_service_ref(&mut self, target: &Target) -> Self::Future { - loop {} - } } impl self::sealed::Sealed<(Target, B1)> for T where diff --git a/src/main.rs b/src/main.rs index 4094f3d..6d4a53a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,4 @@ use std::convert::Infallible; -use std::net::SocketAddr; use futures::future; use hyper::service::make_service_fn; diff --git a/warp/src/filter/mod.rs b/warp/src/filter/mod.rs index 36be1e2..52eb6ee 100644 --- a/warp/src/filter/mod.rs +++ b/warp/src/filter/mod.rs @@ -11,11 +11,6 @@ mod then; mod unify; mod untuple_one; mod wrap; -use std::future::Future; -use futures_util::{future, TryFuture, TryFutureExt}; -pub(crate) use crate::generic::{one, Combine, Either, Func, One, Tuple}; -use crate::reject::{CombineRejection, IsReject, Rejection}; -use crate::route::{Route}; pub(crate) use self::and::And; use self::and_then::AndThen; pub use self::boxed::BoxedFilter; @@ -29,6 +24,11 @@ use self::unify::Unify; use self::untuple_one::UntupleOne; pub use self::wrap::wrap_fn; pub(crate) use self::wrap::{Wrap, WrapSealed}; +pub(crate) use crate::generic::{one, Combine, Either, Func, One, Tuple}; +use crate::reject::{CombineRejection, IsReject, Rejection}; +use crate::route::Route; +use futures_util::{future, TryFuture, TryFutureExt}; +use std::future::Future; pub trait FilterBase { type Extract: Tuple; type Error: IsReject; @@ -45,47 +45,8 @@ pub trait FilterBase { } #[allow(missing_debug_implementations)] pub struct Internal; - - - - - - - - - - - - - - - - - - - - pub trait Filter: FilterBase { - - - - - - - - - - - - - - - - - - - fn and(self, other: F) -> And where Self: Sized, @@ -95,18 +56,7 @@ pub trait Filter: FilterBase { { loop {} } - - - - - - - - - - - - + fn or(self, other: F) -> Or where Self: Filter + Sized, @@ -115,47 +65,7 @@ pub trait Filter: FilterBase { { loop {} } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + fn map(self, fun: F) -> Map where Self: Sized, @@ -163,21 +73,7 @@ pub trait Filter: FilterBase { { loop {} } - - - - - - - - - - - - - - - + fn then(self, fun: F) -> Then where Self: Sized, @@ -186,32 +82,7 @@ pub trait Filter: FilterBase { { loop {} } - - - - - - - - - - - - - - - - - - - - - - - - - - + fn and_then(self, fun: F) -> AndThen where Self: Sized, @@ -221,10 +92,7 @@ pub trait Filter: FilterBase { { loop {} } - - - - + fn or_else(self, fun: F) -> OrElse where Self: Filter + Sized, @@ -234,13 +102,7 @@ pub trait Filter: FilterBase { { loop {} } - - - - - - - + fn recover(self, fun: F) -> Recover where Self: Filter + Sized, @@ -250,28 +112,7 @@ pub trait Filter: FilterBase { { loop {} } - - - - - - - - - - - - - - - - - - - - - - + fn unify(self) -> Unify where Self: Filter,)> + Sized, @@ -279,41 +120,7 @@ pub trait Filter: FilterBase { { loop {} } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + fn untuple_one(self) -> UntupleOne where Self: Filter + Sized, @@ -321,22 +128,7 @@ pub trait Filter: FilterBase { { loop {} } - - - - - - - - - - - - - - - - + fn with(self, wrapper: W) -> W::Wrapped where Self: Sized, @@ -344,30 +136,7 @@ pub trait Filter: FilterBase { { loop {} } - - - - - - - - - - - - - - - - - - - - - - - - + fn boxed(self) -> BoxedFilter where Self: Sized + Send + Sync + 'static, diff --git a/warp/src/filters/path.rs b/warp/src/filters/path.rs index c29f2bb..85fbbbf 100644 --- a/warp/src/filters/path.rs +++ b/warp/src/filters/path.rs @@ -124,41 +124,15 @@ //! like `body` or `headers`. If a different type of filter comes first, a request //! with an invalid body for route `/right-path-wrong-body` may try matching against `/wrong-path` //! and return the error from `/wrong-path` instead of the correct body-related error. -use std::convert::Infallible; -use std::fmt; -use std::str::FromStr; -use futures_util::future; -use http::uri::PathAndQuery; use self::internal::Opaque; use crate::filter::{filter_fn, one, Filter, FilterBase, Internal, One, Tuple}; use crate::reject::{self, Rejection}; use crate::route::Route; - - - - - - - - - - - - - - - - - - - - - - - - - - +use futures_util::future; +use http::uri::PathAndQuery; +use std::convert::Infallible; +use std::fmt; +use std::str::FromStr; pub fn path

(p: P) -> Exact> where @@ -167,8 +141,6 @@ where loop {} } - - #[allow(missing_debug_implementations)] #[derive(Clone, Copy)] pub struct Exact

(P); @@ -185,19 +157,6 @@ where } } - - - - - - - - - - - - - pub fn end() -> impl Filter + Copy { filter_fn(move |route| { if route.path().is_empty() { @@ -208,27 +167,8 @@ pub fn end() -> impl Filter + Copy { }) } - - - - - - - - - - - - - - - - - -pub fn param() -> impl Filter< - Extract = One, - Error = Rejection, -> + Copy { +pub fn param( +) -> impl Filter, Error = Rejection> + Copy { filter_segment(|seg| { tracing::trace!("param?: {:?}", seg); if seg.is_empty() { @@ -238,29 +178,16 @@ pub fn param() -> impl Filter< }) } - - - - - - - - - - - - - - - - pub fn tail() -> impl Filter, Error = Infallible> + Copy { filter_fn(move |route| { let path = path_and_query(route); let idx = route.matched_path_index(); let end = path.path().len() - idx; route.set_unmatched_path(end); - future::ok(one(Tail { path, start_index: idx })) + future::ok(one(Tail { + path, + start_index: idx, + })) }) } @@ -269,7 +196,6 @@ pub struct Tail { start_index: usize, } impl Tail { - pub fn as_str(&self) -> &str { loop {} } @@ -280,28 +206,14 @@ impl fmt::Debug for Tail { } } - - - - - - - - - - - - - - - - - pub fn peek() -> impl Filter, Error = Infallible> + Copy { filter_fn(move |route| { let path = path_and_query(route); let idx = route.matched_path_index(); - future::ok(one(Peek { path, start_index: idx })) + future::ok(one(Peek { + path, + start_index: idx, + })) }) } @@ -310,11 +222,10 @@ pub struct Peek { start_index: usize, } impl Peek { - pub fn as_str(&self) -> &str { loop {} } - + pub fn segments(&self) -> impl Iterator { self.as_str().split('/').filter(|seg| !seg.is_empty()) } @@ -325,43 +236,12 @@ impl fmt::Debug for Peek { } } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - pub fn full() -> impl Filter, Error = Infallible> + Copy { filter_fn(move |route| future::ok(one(FullPath(path_and_query(route))))) } pub struct FullPath(PathAndQuery); impl FullPath { - pub fn as_str(&self) -> &str { loop {} } @@ -388,60 +268,6 @@ fn path_and_query(route: &Route) -> PathAndQuery { loop {} } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #[macro_export] macro_rules! path { ($($pieces:tt)*) => { @@ -487,24 +313,6 @@ macro_rules! __internal_path { }; } - - - - - - - - - - - - - - - - - - fn _path_macro_compile_fail() {} mod internal { #[allow(missing_debug_implementations)] diff --git a/warp/src/filters/trace.rs b/warp/src/filters/trace.rs index 763b8de..ce26421 100644 --- a/warp/src/filters/trace.rs +++ b/warp/src/filters/trace.rs @@ -8,59 +8,19 @@ //! //! [`tracing`]: https://crates.io/crates/tracing //! [`Spans`]: https://docs.rs/tracing/latest/tracing/#spans -use tracing::Span; -use std::net::SocketAddr; -use http::{self}; +use self::internal::WithTrace; use crate::filter::{Filter, WrapSealed}; use crate::reject::IsReject; use crate::reply::Reply; use crate::route::Route; -use self::internal::WithTrace; - - - - - - - - - - - - - - - - - +use http::{self}; +use std::net::SocketAddr; +use tracing::Span; pub fn request() -> Trace) -> Span + Clone> { - trace(|info: Info<'_>| { - loop {} - }) + trace(|info: Info<'_>| loop {}) } - - - - - - - - - - - - - - - - - - - - - pub fn trace(func: F) -> Trace where F: Fn(Info<'_>) -> Span + Clone, @@ -68,37 +28,10 @@ where loop {} } - - - - - - - - - - - - - - - - - - - - - - - pub fn named(name: &'static str) -> Trace) -> Span + Copy> { trace(move |_| tracing::debug_span!("context", "{}", name,)) } - - - - #[derive(Clone, Copy, Debug)] pub struct Trace { func: F, @@ -121,47 +54,46 @@ where } } impl<'a> Info<'a> { - pub fn remote_addr(&self) -> Option { loop {} } - + pub fn method(&self) -> &http::Method { loop {} } - + pub fn path(&self) -> &str { loop {} } - + pub fn version(&self) -> http::Version { loop {} } - + pub fn referer(&self) -> Option<&str> { loop {} } - + pub fn user_agent(&self) -> Option<&str> { loop {} } - + pub fn host(&self) -> Option<&str> { loop {} } - + pub fn request_headers(&self) -> &http::HeaderMap { loop {} } } mod internal { - use futures_util::{future::Inspect, future::MapOk}; use super::{Info, Trace}; use crate::filter::{Filter, FilterBase, Internal}; use crate::reject::IsReject; use crate::reply::Reply; use crate::reply::Response; - + use futures_util::{future::Inspect, future::MapOk}; + #[allow(missing_debug_implementations)] pub struct Traced(pub(super) Response); impl Reply for Traced { @@ -176,7 +108,7 @@ mod internal { pub(super) filter: F, pub(super) trace: Trace, } - use tracing::instrument::{Instrumented}; + use tracing::instrument::Instrumented; use tracing::Span; fn finished_logger(reply: &Result<(Traced,), E>) { loop {}