mirror of
https://github.com/Noratrieb/101844-repro.git
synced 2026-01-14 14:25:02 +01:00
smaller
This commit is contained in:
parent
136f1b4bd9
commit
0f642ee243
2 changed files with 60 additions and 83 deletions
|
|
@ -13,13 +13,7 @@ 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,
|
||||||
|
|
|
||||||
|
|
@ -1,87 +1,70 @@
|
||||||
//! 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
|
||||||
|
S: Clone,
|
||||||
|
{
|
||||||
|
type Response = S;
|
||||||
|
type Error = Infallible;
|
||||||
|
type Future = SharedFuture<S>;
|
||||||
|
|
||||||
use crate::sealed::Sealed;
|
fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
||||||
use std::task::{Context, Poll};
|
todo!()
|
||||||
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,
|
|
||||||
{
|
|
||||||
type Response = S;
|
|
||||||
type Error = Infallible;
|
|
||||||
type Future = SharedFuture<S>;
|
|
||||||
|
|
||||||
fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn call(&mut self, _target: T) -> Self::Future {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
opaque_future! {
|
|
||||||
/// Response future from [`Shared`] services.
|
|
||||||
pub type SharedFuture<S> = futures_util::future::Ready<Result<S, Infallible>>;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait MakeService<Target, Request> {
|
fn call(&mut self, _target: T) -> Self::Future {
|
||||||
type Response;
|
todo!()
|
||||||
type Error;
|
}
|
||||||
type Service: Service<Request, Response = Self::Response, Error = Self::Error>;
|
}
|
||||||
type MakeError;
|
|
||||||
type Future;
|
opaque_future! {
|
||||||
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::MakeError>>;
|
/// Response future from [`Shared`] services.
|
||||||
fn make_service(&mut self, target: Target) -> Self::Future;
|
pub type SharedFuture<S> = futures_util::future::Ready<Result<S, Infallible>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<M, S, Target, Request> Sealed<(Target, Request)> for M
|
pub trait MakeService<Target, Request> {
|
||||||
where
|
type Response;
|
||||||
M: Service<Target, Response = S>,
|
type Error;
|
||||||
S: Service<Request>,
|
type Service: Service<Request, Response = Self::Response, Error = Self::Error>;
|
||||||
{
|
type MakeError;
|
||||||
}
|
type Future;
|
||||||
|
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::MakeError>>;
|
||||||
impl<M, S, Target, Request> MakeService<Target, Request> for M
|
fn make_service(&mut self, target: Target) -> Self::Future;
|
||||||
where
|
}
|
||||||
M: Service<Target, Response = S>,
|
|
||||||
S: Service<Request>,
|
impl<M, S, Target, Request> Sealed<(Target, Request)> for M
|
||||||
{
|
where
|
||||||
type Response = S::Response;
|
M: Service<Target, Response = S>,
|
||||||
type Error = S::Error;
|
S: Service<Request>,
|
||||||
type Service = S;
|
{
|
||||||
type MakeError = M::Error;
|
}
|
||||||
type Future = M::Future;
|
|
||||||
|
impl<M, S, Target, Request> MakeService<Target, Request> for M
|
||||||
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::MakeError>> {
|
where
|
||||||
Service::poll_ready(self, cx)
|
M: Service<Target, Response = S>,
|
||||||
}
|
S: Service<Request>,
|
||||||
|
{
|
||||||
fn make_service(&mut self, target: Target) -> Self::Future {
|
type Response = S::Response;
|
||||||
Service::call(self, target)
|
type Error = S::Error;
|
||||||
}
|
type Service = S;
|
||||||
|
type MakeError = M::Error;
|
||||||
|
type Future = M::Future;
|
||||||
|
|
||||||
|
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::MakeError>> {
|
||||||
|
Service::poll_ready(self, cx)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn make_service(&mut self, target: Target) -> Self::Future {
|
||||||
|
Service::call(self, target)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue