This commit is contained in:
nora 2023-03-07 16:59:20 +01:00
parent b4e7136ad9
commit 1d163b6fef
5 changed files with 50 additions and 555 deletions

View file

@ -27,16 +27,12 @@ where
loop {}
}
}
pub trait MakeServiceRef<Target, ReqBody>: self::sealed::Sealed<(Target, ReqBody)> {
type ResBody: HttpBody;
type Error: Into<Box<dyn StdError + Send + Sync>>;
pub trait MakeServiceRef<Target, ReqBody> {
type ResBody;
type Error;
type Service: HttpService<ReqBody, ResBody = Self::ResBody, Error = Self::Error>;
type MakeError: Into<Box<dyn StdError + Send + Sync>>;
type Future: Future<Output = Result<Self::Service, Self::MakeError>>;
type __DontNameMe: self::sealed::CantImpl;
fn poll_ready_ref(&mut self, cx: &mut task::Context<'_>) -> Poll<Result<(), Self::MakeError>>;
fn make_service_ref(&mut self, target: &Target) -> Self::Future;
}
impl<T, Target, E, ME, S, F, IB, OB> MakeServiceRef<Target, IB> 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<Result<(), Self::MakeError>> {
loop {}
}
fn make_service_ref(&mut self, target: &Target) -> Self::Future {
loop {}
}
}
impl<T, Target, S, B1, B2> self::sealed::Sealed<(Target, B1)> for T
where

View file

@ -1,5 +1,4 @@
use std::convert::Infallible;
use std::net::SocketAddr;
use futures::future;
use hyper::service::make_service_fn;

View file

@ -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<F>(self, other: F) -> And<Self, F>
where
Self: Sized,
@ -95,18 +56,7 @@ pub trait Filter: FilterBase {
{
loop {}
}
fn or<F>(self, other: F) -> Or<Self, F>
where
Self: Filter<Error = Rejection> + Sized,
@ -115,47 +65,7 @@ pub trait Filter: FilterBase {
{
loop {}
}
fn map<F>(self, fun: F) -> Map<Self, F>
where
Self: Sized,
@ -163,21 +73,7 @@ pub trait Filter: FilterBase {
{
loop {}
}
fn then<F>(self, fun: F) -> Then<Self, F>
where
Self: Sized,
@ -186,32 +82,7 @@ pub trait Filter: FilterBase {
{
loop {}
}
fn and_then<F>(self, fun: F) -> AndThen<Self, F>
where
Self: Sized,
@ -221,10 +92,7 @@ pub trait Filter: FilterBase {
{
loop {}
}
fn or_else<F>(self, fun: F) -> OrElse<Self, F>
where
Self: Filter<Error = Rejection> + Sized,
@ -234,13 +102,7 @@ pub trait Filter: FilterBase {
{
loop {}
}
fn recover<F>(self, fun: F) -> Recover<Self, F>
where
Self: Filter<Error = Rejection> + Sized,
@ -250,28 +112,7 @@ pub trait Filter: FilterBase {
{
loop {}
}
fn unify<T>(self) -> Unify<Self>
where
Self: Filter<Extract = (Either<T, T>,)> + Sized,
@ -279,41 +120,7 @@ pub trait Filter: FilterBase {
{
loop {}
}
fn untuple_one<T>(self) -> UntupleOne<Self>
where
Self: Filter<Extract = (T,)> + Sized,
@ -321,22 +128,7 @@ pub trait Filter: FilterBase {
{
loop {}
}
fn with<W>(self, wrapper: W) -> W::Wrapped
where
Self: Sized,
@ -344,30 +136,7 @@ pub trait Filter: FilterBase {
{
loop {}
}
fn boxed(self) -> BoxedFilter<Self::Extract>
where
Self: Sized + Send + Sync + 'static,

View file

@ -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: P) -> Exact<Opaque<P>>
where
@ -167,8 +141,6 @@ where
loop {}
}
#[allow(missing_debug_implementations)]
#[derive(Clone, Copy)]
pub struct Exact<P>(P);
@ -185,19 +157,6 @@ where
}
}
pub fn end() -> impl Filter<Extract = (), Error = Rejection> + Copy {
filter_fn(move |route| {
if route.path().is_empty() {
@ -208,27 +167,8 @@ pub fn end() -> impl Filter<Extract = (), Error = Rejection> + Copy {
})
}
pub fn param<T: FromStr + Send + 'static>() -> impl Filter<
Extract = One<T>,
Error = Rejection,
> + Copy {
pub fn param<T: FromStr + Send + 'static>(
) -> impl Filter<Extract = One<T>, Error = Rejection> + Copy {
filter_segment(|seg| {
tracing::trace!("param?: {:?}", seg);
if seg.is_empty() {
@ -238,29 +178,16 @@ pub fn param<T: FromStr + Send + 'static>() -> impl Filter<
})
}
pub fn tail() -> impl Filter<Extract = One<Tail>, 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<Extract = One<Peek>, 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<Item = &str> {
self.as_str().split('/').filter(|seg| !seg.is_empty())
}
@ -325,43 +236,12 @@ impl fmt::Debug for Peek {
}
}
pub fn full() -> impl Filter<Extract = One<FullPath>, 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)]

View file

@ -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<impl Fn(Info<'_>) -> Span + Clone> {
trace(|info: Info<'_>| {
loop {}
})
trace(|info: Info<'_>| loop {})
}
pub fn trace<F>(func: F) -> Trace<F>
where
F: Fn(Info<'_>) -> Span + Clone,
@ -68,37 +28,10 @@ where
loop {}
}
pub fn named(name: &'static str) -> Trace<impl Fn(Info<'_>) -> Span + Copy> {
trace(move |_| tracing::debug_span!("context", "{}", name,))
}
#[derive(Clone, Copy, Debug)]
pub struct Trace<F> {
func: F,
@ -121,47 +54,46 @@ where
}
}
impl<'a> Info<'a> {
pub fn remote_addr(&self) -> Option<SocketAddr> {
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<FN>,
}
use tracing::instrument::{Instrumented};
use tracing::instrument::Instrumented;
use tracing::Span;
fn finished_logger<E: IsReject>(reply: &Result<(Traced,), E>) {
loop {}