Skip to content

Commit

Permalink
remove future type param (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkw authored and Harry Barber committed Jan 6, 2021
1 parent b19cd79 commit 0b108ca
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 25 deletions.
29 changes: 9 additions & 20 deletions tower/src/util/and_then.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::marker::PhantomData;
use std::task::{Context, Poll};

use futures_core::TryFuture;
Expand All @@ -10,24 +9,19 @@ use tower_service::Service;
///
/// [`and_then`]: crate::util::ServiceExt::and_then
#[derive(Clone, Debug)]
pub struct AndThen<S, F, Fut> {
pub struct AndThen<S, F> {
inner: S,
f: F,
_fut: PhantomData<Fut>,
}

impl<S, F, Fut> AndThen<S, F, Fut> {
impl<S, F> AndThen<S, F> {
/// Creates a new `AndThen` service.
pub fn new(inner: S, f: F) -> Self {
AndThen {
f,
inner,
_fut: Default::default(),
}
AndThen { f, inner }
}
}

impl<S, F, Request, Fut> Service<Request> for AndThen<S, F, Fut>
impl<S, F, Request, Fut> Service<Request> for AndThen<S, F>
where
S: Service<Request>,
F: FnOnce(S::Response) -> Fut + Clone,
Expand All @@ -50,32 +44,27 @@ where
///
/// [`Layer`]: tower_layer::Layer
#[derive(Debug)]
pub struct AndThenLayer<F, Fut> {
pub struct AndThenLayer<F> {
f: F,
_fut: PhantomData<Fut>,
}

impl<F, Fut> AndThenLayer<F, Fut> {
impl<F> AndThenLayer<F> {
/// Creates a new [`AndThenLayer`] layer.
pub fn new(f: F) -> Self {
AndThenLayer {
f,
_fut: Default::default(),
}
AndThenLayer { f }
}
}

impl<S, F, Fut> Layer<S> for AndThenLayer<F, Fut>
impl<S, F> Layer<S> for AndThenLayer<F>
where
F: Clone,
{
type Service = AndThen<S, F, Fut>;
type Service = AndThen<S, F>;

fn layer(&self, inner: S) -> Self::Service {
AndThen {
f: self.f.clone(),
inner,
_fut: Default::default(),
}
}
}
11 changes: 6 additions & 5 deletions tower/src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,13 @@ pub trait ServiceExt<Request>: tower_service::Service<Request> {
{
CallAll::new(self, reqs)
}
fn and_then<F, Fut>(self, f: F) -> AndThen<Self, F, Fut>

fn and_then<F>(self, f: F) -> AndThen<Self, F>
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
Expand Down

0 comments on commit 0b108ca

Please sign in to comment.