From deae0e7f2576a40e8e40a86945077cbb18766400 Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Mon, 23 Nov 2020 11:24:15 -0800 Subject: [PATCH] remove future type param --- tower/src/util/and_then.rs | 29 +++++++++-------------------- tower/src/util/mod.rs | 11 ++++++----- 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/tower/src/util/and_then.rs b/tower/src/util/and_then.rs index 9215fa085..bc99f096d 100644 --- a/tower/src/util/and_then.rs +++ b/tower/src/util/and_then.rs @@ -1,4 +1,3 @@ -use std::marker::PhantomData; use std::task::{Context, Poll}; use futures_core::TryFuture; @@ -10,24 +9,19 @@ use tower_service::Service; /// /// [`and_then`]: crate::util::ServiceExt::and_then #[derive(Clone, Debug)] -pub struct AndThen { +pub struct AndThen { inner: S, f: F, - _fut: PhantomData, } -impl AndThen { +impl AndThen { /// Creates a new `AndThen` service. pub fn new(inner: S, f: F) -> Self { - AndThen { - f, - inner, - _fut: Default::default(), - } + AndThen { f, inner } } } -impl Service for AndThen +impl Service for AndThen where S: Service, F: FnOnce(S::Response) -> Fut + Clone, @@ -50,32 +44,27 @@ where /// /// [`Layer`]: tower_layer::Layer #[derive(Debug)] -pub struct AndThenLayer { +pub struct AndThenLayer { f: F, - _fut: PhantomData, } -impl AndThenLayer { +impl AndThenLayer { /// Creates a new [`AndThenLayer`] layer. pub fn new(f: F) -> Self { - AndThenLayer { - f, - _fut: Default::default(), - } + AndThenLayer { f } } } -impl Layer for AndThenLayer +impl Layer for AndThenLayer where F: Clone, { - type Service = AndThen; + type Service = AndThen; fn layer(&self, inner: S) -> Self::Service { AndThen { f: self.f.clone(), inner, - _fut: Default::default(), } } } diff --git a/tower/src/util/mod.rs b/tower/src/util/mod.rs index 33ab1a318..d9b85df87 100644 --- a/tower/src/util/mod.rs +++ b/tower/src/util/mod.rs @@ -92,12 +92,13 @@ pub trait ServiceExt: tower_service::Service { { CallAll::new(self, reqs) } - - fn and_then(self, f: F) -> AndThen + + fn and_then(self, f: F) -> AndThen where - Self: Sized, - F: FnOnce(Self::Response) -> Fut + Clone { - AndThen::new(self, f) + Self: Sized, + F: Clone, + { + AndThen::new(self, f) } /// Maps this service's response value to a different value. This does not