This commit is contained in:
nora 2022-09-15 21:51:46 +02:00
parent 136f1b4bd9
commit 0f642ee243
2 changed files with 60 additions and 83 deletions

View file

@ -14,12 +14,6 @@ macro_rules! opaque_future {
} }
} }
impl<$($param),+> std::fmt::Debug for $name<$($param),+> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_tuple(stringify!($name)).field(&format_args!("...")).finish()
}
}
impl<$($param),+> std::future::Future for $name<$($param),+> impl<$($param),+> std::future::Future for $name<$($param),+>
where where
$actual: std::future::Future, $actual: std::future::Future,

View file

@ -1,34 +1,19 @@
//! Trait aliases for Services that produce specific types of Responses. //! Trait aliases for Services that produce specific types of Responses.
pub use self::make_service::shared::Shared; use crate::sealed::Sealed;
pub use self::make_service::MakeService; use crate::Service;
use std::task::{Context, Poll};
pub mod future { use std::convert::Infallible;
//! Future types
pub use super::make_service::shared::SharedFuture; pub struct Shared<S> {
service: S,
} }
mod make_service { impl<S, T> Service<T> for Shared<S>
//! Contains [`MakeService`] which is a trait alias for a [`Service`] of [`Service`]s. where
use crate::sealed::Sealed;
use std::task::{Context, Poll};
use crate::Service;
pub mod shared {
use std::convert::Infallible;
use std::task::{Context, Poll};
use crate::Service;
pub struct Shared<S> {
service: S,
}
impl<S, T> Service<T> for Shared<S>
where
S: Clone, S: Clone,
{ {
type Response = S; type Response = S;
type Error = Infallible; type Error = Infallible;
type Future = SharedFuture<S>; type Future = SharedFuture<S>;
@ -40,15 +25,14 @@ mod make_service {
fn call(&mut self, _target: T) -> Self::Future { fn call(&mut self, _target: T) -> Self::Future {
todo!() todo!()
} }
} }
opaque_future! { opaque_future! {
/// Response future from [`Shared`] services. /// Response future from [`Shared`] services.
pub type SharedFuture<S> = futures_util::future::Ready<Result<S, Infallible>>; pub type SharedFuture<S> = futures_util::future::Ready<Result<S, Infallible>>;
} }
}
pub trait MakeService<Target, Request> { pub trait MakeService<Target, Request> {
type Response; type Response;
type Error; type Error;
type Service: Service<Request, Response = Self::Response, Error = Self::Error>; type Service: Service<Request, Response = Self::Response, Error = Self::Error>;
@ -56,20 +40,20 @@ mod make_service {
type Future; type Future;
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::MakeError>>; fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::MakeError>>;
fn make_service(&mut self, target: Target) -> Self::Future; fn make_service(&mut self, target: Target) -> Self::Future;
} }
impl<M, S, Target, Request> Sealed<(Target, Request)> for M impl<M, S, Target, Request> Sealed<(Target, Request)> for M
where where
M: Service<Target, Response = S>, M: Service<Target, Response = S>,
S: Service<Request>, S: Service<Request>,
{ {
} }
impl<M, S, Target, Request> MakeService<Target, Request> for M impl<M, S, Target, Request> MakeService<Target, Request> for M
where where
M: Service<Target, Response = S>, M: Service<Target, Response = S>,
S: Service<Request>, S: Service<Request>,
{ {
type Response = S::Response; type Response = S::Response;
type Error = S::Error; type Error = S::Error;
type Service = S; type Service = S;
@ -83,5 +67,4 @@ mod make_service {
fn make_service(&mut self, target: Target) -> Self::Future { fn make_service(&mut self, target: Target) -> Self::Future {
Service::call(self, target) Service::call(self, target)
} }
}
} }