From 0f642ee243e396cc213f0b1a10acd528f9881e6d Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Thu, 15 Sep 2022 21:51:46 +0200 Subject: [PATCH] smaller --- tower/tower/src/macros.rs | 8 +-- tower/tower/src/make.rs | 135 +++++++++++++++++--------------------- 2 files changed, 60 insertions(+), 83 deletions(-) diff --git a/tower/tower/src/macros.rs b/tower/tower/src/macros.rs index bfdf0d7..1d3722e 100644 --- a/tower/tower/src/macros.rs +++ b/tower/tower/src/macros.rs @@ -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),+> where $actual: std::future::Future, diff --git a/tower/tower/src/make.rs b/tower/tower/src/make.rs index 3134788..3a69372 100644 --- a/tower/tower/src/make.rs +++ b/tower/tower/src/make.rs @@ -1,87 +1,70 @@ //! Trait aliases for Services that produce specific types of Responses. -pub use self::make_service::shared::Shared; -pub use self::make_service::MakeService; +use crate::sealed::Sealed; +use crate::Service; +use std::task::{Context, Poll}; -pub mod future { - //! Future types +use std::convert::Infallible; - pub use super::make_service::shared::SharedFuture; +pub struct Shared { + service: S, } -mod make_service { - //! Contains [`MakeService`] which is a trait alias for a [`Service`] of [`Service`]s. +impl Service for Shared +where + S: Clone, +{ + type Response = S; + type Error = Infallible; + type Future = SharedFuture; - 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 { - service: S, - } - - impl Service for Shared - where - S: Clone, - { - type Response = S; - type Error = Infallible; - type Future = SharedFuture; - - fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll> { - todo!() - } - - fn call(&mut self, _target: T) -> Self::Future { - todo!() - } - } - - opaque_future! { - /// Response future from [`Shared`] services. - pub type SharedFuture = futures_util::future::Ready>; - } + fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll> { + todo!() } - pub trait MakeService { - type Response; - type Error; - type Service: Service; - type MakeError; - type Future; - fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll>; - fn make_service(&mut self, target: Target) -> Self::Future; - } - - impl Sealed<(Target, Request)> for M - where - M: Service, - S: Service, - { - } - - impl MakeService for M - where - M: Service, - S: Service, - { - type Response = S::Response; - type Error = S::Error; - type Service = S; - type MakeError = M::Error; - type Future = M::Future; - - fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll> { - Service::poll_ready(self, cx) - } - - fn make_service(&mut self, target: Target) -> Self::Future { - Service::call(self, target) - } + fn call(&mut self, _target: T) -> Self::Future { + todo!() + } +} + +opaque_future! { + /// Response future from [`Shared`] services. + pub type SharedFuture = futures_util::future::Ready>; +} + +pub trait MakeService { + type Response; + type Error; + type Service: Service; + type MakeError; + type Future; + fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll>; + fn make_service(&mut self, target: Target) -> Self::Future; +} + +impl Sealed<(Target, Request)> for M +where + M: Service, + S: Service, +{ +} + +impl MakeService for M +where + M: Service, + S: Service, +{ + type Response = S::Response; + type Error = S::Error; + type Service = S; + type MakeError = M::Error; + type Future = M::Future; + + fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll> { + Service::poll_ready(self, cx) + } + + fn make_service(&mut self, target: Target) -> Self::Future { + Service::call(self, target) } }