Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove future type param #1

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -92,12 +92,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