diff --git a/actix-service/src/and_then.rs b/actix-service/src/and_then.rs
index c52f4da1..ee0f5e18 100644
--- a/actix-service/src/and_then.rs
+++ b/actix-service/src/and_then.rs
@@ -1,3 +1,5 @@
+use std::marker::PhantomData;
+
use futures::{try_ready, Async, Future, Poll};
use super::{IntoNewService, NewService, Service};
@@ -14,10 +16,10 @@ pub struct AndThen {
impl AndThen {
/// Create new `AndThen` combinator
- pub fn new(a: A, b: B) -> Self
+ pub fn new(a: A, b: B) -> Self
where
- A: Service,
- B: Service,
+ A: Service,
+ B: Service,
{
Self { a, b: Cell::new(b) }
}
@@ -35,39 +37,40 @@ where
}
}
-impl Service for AndThen
+impl Service for AndThen
where
- A: Service,
- B: Service,
+ A: Service,
+ B: Service,
{
+ type Request = A::Request;
type Response = B::Response;
type Error = A::Error;
- type Future = AndThenFuture;
+ type Future = AndThenFuture;
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
try_ready!(self.a.poll_ready());
self.b.get_mut().poll_ready()
}
- fn call(&mut self, req: R) -> Self::Future {
+ fn call(&mut self, req: A::Request) -> Self::Future {
AndThenFuture::new(self.a.call(req), self.b.clone())
}
}
-pub struct AndThenFuture
+pub struct AndThenFuture
where
- A: Service,
- B: Service,
+ A: Service,
+ B: Service,
{
b: Cell,
fut_b: Option,
fut_a: Option,
}
-impl AndThenFuture
+impl AndThenFuture
where
- A: Service,
- B: Service,
+ A: Service,
+ B: Service,
{
fn new(a: A::Future, b: Cell) -> Self {
AndThenFuture {
@@ -78,10 +81,10 @@ where
}
}
-impl Future for AndThenFuture
+impl Future for AndThenFuture
where
- A: Service,
- B: Service,
+ A: Service,
+ B: Service,
{
type Item = B::Response;
type Error = A::Error;
@@ -104,43 +107,46 @@ where
}
/// `AndThenNewService` new service combinator
-pub struct AndThenNewService {
+pub struct AndThenNewService {
a: A,
b: B,
+ _t: PhantomData,
}
-impl AndThenNewService {
+impl AndThenNewService {
/// Create new `AndThen` combinator
- pub fn new>(a: A, f: F) -> Self
+ pub fn new>(a: A, f: F) -> Self
where
- A: NewService,
- B: NewService,
+ A: NewService,
+ B: NewService,
{
Self {
a,
b: f.into_new_service(),
+ _t: PhantomData,
}
}
}
-impl NewService for AndThenNewService
+impl NewService for AndThenNewService
where
- A: NewService,
- B: NewService,
+ A: NewService,
+ B: NewService,
{
+ type Request = A::Request;
type Response = B::Response;
type Error = A::Error;
type Service = AndThen;
type InitError = A::InitError;
- type Future = AndThenNewServiceFuture;
+ type Future = AndThenNewServiceFuture;
fn new_service(&self, cfg: &C) -> Self::Future {
AndThenNewServiceFuture::new(self.a.new_service(cfg), self.b.new_service(cfg))
}
}
-impl Clone for AndThenNewService
+impl Clone for AndThenNewService
where
A: Clone,
B: Clone,
@@ -149,14 +155,15 @@ where
Self {
a: self.a.clone(),
b: self.b.clone(),
+ _t: PhantomData,
}
}
}
-pub struct AndThenNewServiceFuture
+pub struct AndThenNewServiceFuture
where
- A: NewService,
- B: NewService,
+ A: NewService,
+ B: NewService,
{
fut_b: B::Future,
fut_a: A::Future,
@@ -164,10 +171,10 @@ where
b: Option,
}
-impl AndThenNewServiceFuture
+impl AndThenNewServiceFuture
where
- A: NewService,
- B: NewService,
+ A: NewService,
+ B: NewService,
{
fn new(fut_a: A::Future, fut_b: B::Future) -> Self {
AndThenNewServiceFuture {
@@ -179,10 +186,10 @@ where
}
}
-impl Future for AndThenNewServiceFuture
+impl Future for AndThenNewServiceFuture
where
- A: NewService,
- B: NewService,
+ A: NewService,
+ B: NewService,
{
type Item = AndThen;
type Error = A::InitError;
@@ -222,7 +229,8 @@ mod tests {
use crate::{NewService, Service, ServiceExt};
struct Srv1(Rc>);
- impl Service<&'static str> for Srv1 {
+ impl Service for Srv1 {
+ type Request = &'static str;
type Response = &'static str;
type Error = ();
type Future = FutureResult;
@@ -240,7 +248,8 @@ mod tests {
#[derive(Clone)]
struct Srv2(Rc>);
- impl Service<&'static str> for Srv2 {
+ impl Service for Srv2 {
+ type Request = &'static str;
type Response = (&'static str, &'static str);
type Error = ();
type Future = FutureResult;
diff --git a/actix-service/src/and_then_apply.rs b/actix-service/src/and_then_apply.rs
index 452f86d1..7ea0dab3 100644
--- a/actix-service/src/and_then_apply.rs
+++ b/actix-service/src/and_then_apply.rs
@@ -1,4 +1,3 @@
-use std::marker::PhantomData;
use std::rc::Rc;
use futures::{Async, Future, Poll};
@@ -8,22 +7,22 @@ use crate::from_err::FromErr;
use crate::{NewService, Transform};
/// `Apply` new service combinator
-pub struct AndThenTransform {
+pub struct AndThenTransform {
a: A,
b: B,
t: Rc,
- _t: PhantomData ,
+ _t: std::marker::PhantomData,
}
-impl AndThenTransform {
+impl AndThenTransform
+where
+ A: NewService,
+ B: NewService,
+ T: Transform,
+ T::Error: From,
+{
/// Create new `ApplyNewService` new service instance
- pub fn new(t: T, a: A, b: B) -> Self
- where
- A: NewService,
- B: NewService ,
- T: Transform,
- T::Error: From,
- {
+ pub fn new(t: T, a: A, b: B) -> Self {
Self {
a,
b,
@@ -33,7 +32,7 @@ impl AndThenTransform {
}
}
-impl Clone for AndThenTransform
+impl Clone for AndThenTransform
where
A: Clone,
B: Clone,
@@ -48,19 +47,20 @@ where
}
}
-impl NewService for AndThenTransform
+impl NewService for AndThenTransform
where
- A: NewService,
- B: NewService ,
- T: Transform,
+ A: NewService,
+ B: NewService,
+ T: Transform,
T::Error: From,
{
+ type Request = A::Request;
type Response = T::Response;
type Error = T::Error;
type InitError = T::InitError;
type Service = AndThen, T::Transform>;
- type Future = AndThenTransformFuture;
+ type Future = AndThenTransformFuture;
fn new_service(&self, cfg: &C) -> Self::Future {
AndThenTransformFuture {
@@ -74,11 +74,11 @@ where
}
}
-pub struct AndThenTransformFuture
+pub struct AndThenTransformFuture
where
- A: NewService,
- B: NewService ,
- T: Transform,
+ A: NewService,
+ B: NewService,
+ T: Transform,
T::Error: From,
{
fut_a: A::Future,
@@ -89,11 +89,11 @@ where
t_cell: Rc,
}
-impl Future for AndThenTransformFuture
+impl Future for AndThenTransformFuture
where
- A: NewService,
- B: NewService ,
- T: Transform,
+ A: NewService,
+ B: NewService,
+ T: Transform,
T::Error: From,
{
type Item = AndThen, T::Transform>;
@@ -138,7 +138,8 @@ mod tests {
#[derive(Clone)]
struct Srv;
- impl Service<()> for Srv {
+ impl Service for Srv {
+ type Request = ();
type Response = ();
type Error = ();
type Future = FutureResult<(), ()>;
diff --git a/actix-service/src/and_then_apply_fn.rs b/actix-service/src/and_then_apply_fn.rs
index 8eafb738..41b536dc 100644
--- a/actix-service/src/and_then_apply_fn.rs
+++ b/actix-service/src/and_then_apply_fn.rs
@@ -6,23 +6,30 @@ use super::{IntoNewService, IntoService, NewService, Service};
use crate::cell::Cell;
/// `Apply` service combinator
-pub struct AndThenApply {
+pub struct AndThenApply
+where
+ A: Service,
+ B: Service,
+ F: FnMut(A::Response, &mut B) -> Out,
+ Out: IntoFuture,
+ Out::Error: Into,
+{
a: A,
b: Cell,
f: Cell,
- r: PhantomData<(Out, AReq, BReq)>,
+ r: PhantomData<(Out,)>,
}
-impl AndThenApply
+impl AndThenApply
where
- A: Service,
- B: Service,
+ A: Service,
+ B: Service,
F: FnMut(A::Response, &mut B) -> Out,
Out: IntoFuture,
Out::Error: Into,
{
/// Create new `Apply` combinator
- pub fn new, B1: IntoService>(a: A1, b: B1, f: F) -> Self {
+ pub fn new, B1: IntoService>(a: A1, b: B1, f: F) -> Self {
Self {
f: Cell::new(f),
a: a.into_service(),
@@ -32,9 +39,13 @@ where
}
}
-impl Clone for AndThenApply
+impl Clone for AndThenApply
where
- A: Clone,
+ A: Service + Clone,
+ B: Service,
+ F: FnMut(A::Response, &mut B) -> Out,
+ Out: IntoFuture,
+ Out::Error: Into,
{
fn clone(&self) -> Self {
AndThenApply {
@@ -46,38 +57,38 @@ where
}
}
-impl Service for AndThenApply
+impl Service for AndThenApply
where
- A: Service,
- B: Service,
+ A: Service,
+ B: Service,
F: FnMut(A::Response, &mut B) -> Out,
Out: IntoFuture,
Out::Error: Into,
{
+ type Request = A::Request;
type Response = Out::Item;
type Error = A::Error;
- type Future = AndThenApplyFuture;
+ type Future = AndThenApplyFuture;
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
try_ready!(self.a.poll_ready());
self.b.get_mut().poll_ready()
}
- fn call(&mut self, req: AReq) -> Self::Future {
+ fn call(&mut self, req: A::Request) -> Self::Future {
AndThenApplyFuture {
b: self.b.clone(),
f: self.f.clone(),
fut_b: None,
fut_a: Some(self.a.call(req)),
- _t: PhantomData,
}
}
}
-pub struct AndThenApplyFuture
+pub struct AndThenApplyFuture
where
- A: Service,
- B: Service,
+ A: Service,
+ B: Service,
F: FnMut(A::Response, &mut B) -> Out,
Out: IntoFuture,
Out::Error: Into,
@@ -86,13 +97,12 @@ where
f: Cell,
fut_a: Option,
fut_b: Option,
- _t: PhantomData<(AReq, BReq)>,
}
-impl Future for AndThenApplyFuture
+impl Future for AndThenApplyFuture
where
- A: Service,
- B: Service,
+ A: Service,
+ B: Service,
F: FnMut(A::Response, &mut B) -> Out,
Out: IntoFuture,
Out::Error: Into,
@@ -119,23 +129,23 @@ where
}
/// `ApplyNewService` new service combinator
-pub struct AndThenApplyNewService {
+pub struct AndThenApplyNewService {
a: A,
b: B,
f: Cell,
- r: PhantomData<(Out, AReq, BReq, Cfg)>,
+ r: PhantomData<(Out, Cfg)>,
}
-impl AndThenApplyNewService
+impl AndThenApplyNewService
where
- A: NewService,
- B: NewService,
+ A: NewService,
+ B: NewService,
F: FnMut(A::Response, &mut B::Service) -> Out,
Out: IntoFuture,
Out::Error: Into,
{
/// Create new `ApplyNewService` new service instance
- pub fn new, B1: IntoNewService>(
+ pub fn new, B1: IntoNewService>(
a: A1,
b: B1,
f: F,
@@ -149,8 +159,7 @@ where
}
}
-impl Clone
- for AndThenApplyNewService
+impl Clone for AndThenApplyNewService
where
A: Clone,
B: Clone,
@@ -165,21 +174,21 @@ where
}
}
-impl NewService
- for AndThenApplyNewService
+impl NewService for AndThenApplyNewService
where
- A: NewService,
- B: NewService,
+ A: NewService,
+ B: NewService,
F: FnMut(A::Response, &mut B::Service) -> Out,
Out: IntoFuture,
Out::Error: Into,
{
+ type Request = A::Request;
type Response = Out::Item;
type Error = A::Error;
- type Service = AndThenApply;
+ type Service = AndThenApply;
type InitError = A::InitError;
- type Future = AndThenApplyNewServiceFuture;
+ type Future = AndThenApplyNewServiceFuture;
fn new_service(&self, cfg: &Cfg) -> Self::Future {
AndThenApplyNewServiceFuture {
@@ -192,10 +201,10 @@ where
}
}
-pub struct AndThenApplyNewServiceFuture
+pub struct AndThenApplyNewServiceFuture
where
- A: NewService,
- B: NewService,
+ A: NewService,
+ B: NewService,
F: FnMut(A::Response, &mut B::Service) -> Out,
Out: IntoFuture,
Out::Error: Into,
@@ -207,16 +216,15 @@ where
b: Option,
}
-impl Future
- for AndThenApplyNewServiceFuture
+impl Future for AndThenApplyNewServiceFuture
where
- A: NewService,
- B: NewService,
+ A: NewService,
+ B: NewService,
F: FnMut(A::Response, &mut B::Service) -> Out,
Out: IntoFuture,
Out::Error: Into,
{
- type Item = AndThenApply;
+ type Item = AndThenApply;
type Error = A::InitError;
fn poll(&mut self) -> Poll {
@@ -255,7 +263,8 @@ mod tests {
#[derive(Clone)]
struct Srv;
- impl Service<()> for Srv {
+ impl Service for Srv {
+ type Request = ();
type Response = ();
type Error = ();
type Future = FutureResult<(), ()>;
diff --git a/actix-service/src/apply.rs b/actix-service/src/apply.rs
index bf794039..d5dda2d4 100644
--- a/actix-service/src/apply.rs
+++ b/actix-service/src/apply.rs
@@ -5,23 +5,24 @@ use futures::{Async, Future, IntoFuture, Poll};
use super::{IntoNewService, IntoService, NewService, Service};
/// `Apply` service combinator
-pub struct Apply {
+pub struct Apply
+where
+ T: Service,
+{
service: T,
f: F,
- r: PhantomData<(R, In, Out)>,
+ r: PhantomData<(In, Out)>,
}
-impl Apply
+impl Apply
where
+ T: Service,
F: FnMut(In, &mut T) -> Out,
+ Out: IntoFuture,
+ Out::Error: From,
{
/// Create new `Apply` combinator
- pub fn new>(service: I, f: F) -> Self
- where
- T: Service,
- Out: IntoFuture,
- Out::Error: From,
- {
+ pub fn new>(service: I, f: F) -> Self {
Self {
service: service.into_service(),
f,
@@ -30,9 +31,9 @@ where
}
}
-impl Clone for Apply
+impl Clone for Apply
where
- T: Clone,
+ T: Service + Clone,
F: Clone,
{
fn clone(&self) -> Self {
@@ -44,13 +45,14 @@ where
}
}
-impl Service for Apply
+impl Service for Apply
where
- T: Service,
+ T: Service,
F: FnMut(In, &mut T) -> Out,
Out: IntoFuture,
Out::Error: From,
{
+ type Request = In;
type Response = Out::Item;
type Error = Out::Error;
type Future = Out::Future;
@@ -65,21 +67,24 @@ where
}
/// `ApplyNewService` new service combinator
-pub struct ApplyNewService {
+pub struct ApplyNewService
+where
+ T: NewService,
+{
service: T,
f: F,
- r: PhantomData<(In, Out, Req)>,
+ r: PhantomData<(In, Out, Cfg)>,
}
-impl ApplyNewService {
+impl ApplyNewService
+where
+ T: NewService,
+ F: FnMut(In, &mut T::Service) -> Out + Clone,
+ Out: IntoFuture,
+ Out::Error: From,
+{
/// Create new `ApplyNewService` new service instance
- pub fn new>(service: F1, f: F) -> Self
- where
- T: NewService,
- F: FnMut(In, &mut T::Service) -> Out + Clone,
- Out: IntoFuture,
- Out::Error: From,
- {
+ pub fn new>(service: F1, f: F) -> Self {
Self {
f,
service: service.into_new_service(),
@@ -88,10 +93,11 @@ impl ApplyNewService {
}
}
-impl Clone for ApplyNewService
+impl Clone for ApplyNewService
where
- T: Clone,
- F: Clone,
+ T: NewService + Clone,
+ F: FnMut(In, &mut T::Service) -> Out + Clone,
+ Out: IntoFuture,
{
fn clone(&self) -> Self {
Self {
@@ -102,28 +108,29 @@ where
}
}
-impl NewService for ApplyNewService
+impl NewService for ApplyNewService
where
- T: NewService,
+ T: NewService,
F: FnMut(In, &mut T::Service) -> Out + Clone,
Out: IntoFuture,
Out::Error: From,
{
+ type Request = In;
type Response = Out::Item;
type Error = Out::Error;
- type Service = Apply;
+ type Service = Apply;
type InitError = T::InitError;
- type Future = ApplyNewServiceFuture | |