1
0
mirror of https://github.com/fafhrd91/actix-net synced 2025-08-21 15:05:37 +02:00

revert generic Request change

This commit is contained in:
Nikolay Kim
2019-03-09 06:36:23 -08:00
parent 2099629fe3
commit 6bbbdba921
16 changed files with 563 additions and 485 deletions

View File

@@ -16,9 +16,9 @@ pub struct MapErr<A, F, E> {
impl<A, F, E> MapErr<A, F, E> {
/// Create new `MapErr` combinator
pub fn new<R>(service: A, f: F) -> Self
pub fn new(service: A, f: F) -> Self
where
A: Service<R>,
A: Service,
F: Fn(A::Error) -> E,
{
Self {
@@ -43,39 +43,47 @@ where
}
}
impl<A, F, E, R> Service<R> for MapErr<A, F, E>
impl<A, F, E> Service for MapErr<A, F, E>
where
A: Service<R>,
A: Service,
F: Fn(A::Error) -> E + Clone,
{
type Request = A::Request;
type Response = A::Response;
type Error = E;
type Future = MapErrFuture<A, F, E, R>;
type Future = MapErrFuture<A, F, E>;
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
self.service.poll_ready().map_err(&self.f)
}
fn call(&mut self, req: R) -> Self::Future {
MapErrFuture {
fut: self.service.call(req),
f: self.f.clone(),
}
fn call(&mut self, req: A::Request) -> Self::Future {
MapErrFuture::new(self.service.call(req), self.f.clone())
}
}
pub struct MapErrFuture<A, F, E, R>
pub struct MapErrFuture<A, F, E>
where
A: Service<R>,
A: Service,
F: Fn(A::Error) -> E,
{
f: F,
fut: A::Future,
}
impl<A, F, E, R> Future for MapErrFuture<A, F, E, R>
impl<A, F, E> MapErrFuture<A, F, E>
where
A: Service<R>,
A: Service,
F: Fn(A::Error) -> E,
{
fn new(fut: A::Future, f: F) -> Self {
MapErrFuture { f, fut }
}
}
impl<A, F, E> Future for MapErrFuture<A, F, E>
where
A: Service,
F: Fn(A::Error) -> E,
{
type Item = A::Response;
@@ -98,9 +106,9 @@ pub struct MapErrNewService<A, F, E, C> {
impl<A, F, E, C> MapErrNewService<A, F, E, C> {
/// Create new `MapErr` new service instance
pub fn new<R>(a: A, f: F) -> Self
pub fn new(a: A, f: F) -> Self
where
A: NewService<R, C>,
A: NewService<C>,
F: Fn(A::Error) -> E,
{
Self {
@@ -125,35 +133,36 @@ where
}
}
impl<A, F, E, R, C> NewService<R, C> for MapErrNewService<A, F, E, C>
impl<A, F, E, C> NewService<C> for MapErrNewService<A, F, E, C>
where
A: NewService<R, C>,
A: NewService<C>,
F: Fn(A::Error) -> E + Clone,
{
type Request = A::Request;
type Response = A::Response;
type Error = E;
type Service = MapErr<A::Service, F, E>;
type InitError = A::InitError;
type Future = MapErrNewServiceFuture<A, F, E, R, C>;
type Future = MapErrNewServiceFuture<A, F, E, C>;
fn new_service(&self, cfg: &C) -> Self::Future {
MapErrNewServiceFuture::new(self.a.new_service(cfg), self.f.clone())
}
}
pub struct MapErrNewServiceFuture<A, F, E, R, C>
pub struct MapErrNewServiceFuture<A, F, E, C>
where
A: NewService<R, C>,
A: NewService<C>,
F: Fn(A::Error) -> E,
{
fut: A::Future,
f: F,
}
impl<A, F, E, R, C> MapErrNewServiceFuture<A, F, E, R, C>
impl<A, F, E, C> MapErrNewServiceFuture<A, F, E, C>
where
A: NewService<R, C>,
A: NewService<C>,
F: Fn(A::Error) -> E,
{
fn new(fut: A::Future, f: F) -> Self {
@@ -161,9 +170,9 @@ where
}
}
impl<A, F, E, R, C> Future for MapErrNewServiceFuture<A, F, E, R, C>
impl<A, F, E, C> Future for MapErrNewServiceFuture<A, F, E, C>
where
A: NewService<R, C>,
A: NewService<C>,
F: Fn(A::Error) -> E + Clone,
{
type Item = MapErr<A::Service, F, E>;
@@ -187,7 +196,8 @@ mod tests {
struct Srv;
impl Service<()> for Srv {
impl Service for Srv {
type Request = ();
type Response = ();
type Error = ();
type Future = FutureResult<(), ()>;