diff --git a/actix-service/src/map_err.rs b/actix-service/src/map_err.rs index 7b1ac2ab..aad0f421 100644 --- a/actix-service/src/map_err.rs +++ b/actix-service/src/map_err.rs @@ -9,26 +9,25 @@ use pin_project_lite::pin_project; use super::{Service, ServiceFactory}; -/// Service for the `map_err` combinator, changing the type of a service's -/// error. +/// Service for the `map_err` combinator, changing the type of a service's error. /// /// This is created by the `ServiceExt::map_err` method. pub struct MapErr { service: S, - f: F, + mapper: F, _t: PhantomData<(E, Req)>, } impl MapErr { /// Create new `MapErr` combinator - pub(crate) fn new(service: S, f: F) -> Self + pub(crate) fn new(service: S, mapper: F) -> Self where S: Service, F: Fn(S::Error) -> E, { Self { service, - f, + mapper, _t: PhantomData, } } @@ -42,7 +41,7 @@ where fn clone(&self) -> Self { MapErr { service: self.service.clone(), - f: self.f.clone(), + mapper: self.mapper.clone(), _t: PhantomData, } } @@ -58,11 +57,11 @@ where type Future = MapErrFuture; fn poll_ready(&self, ctx: &mut Context<'_>) -> Poll> { - self.service.poll_ready(ctx).map_err(&self.f) + self.service.poll_ready(ctx).map_err(&self.mapper) } fn call(&self, req: Req) -> Self::Future { - MapErrFuture::new(self.service.call(req), self.f.clone()) + MapErrFuture::new(self.service.call(req), self.mapper.clone()) } } @@ -105,23 +104,23 @@ where /// service's error. /// /// This is created by the `NewServiceExt::map_err` method. -pub struct MapErrServiceFactory +pub struct MapErrServiceFactory where - A: ServiceFactory, - F: Fn(A::Error) -> E + Clone, + SF: ServiceFactory, + F: Fn(SF::Error) -> E + Clone, { - a: A, + a: SF, f: F, e: PhantomData<(E, Req)>, } -impl MapErrServiceFactory +impl MapErrServiceFactory where - A: ServiceFactory, - F: Fn(A::Error) -> E + Clone, + SF: ServiceFactory, + F: Fn(SF::Error) -> E + Clone, { /// Create new `MapErr` new service instance - pub(crate) fn new(a: A, f: F) -> Self { + pub(crate) fn new(a: SF, f: F) -> Self { Self { a, f, @@ -130,10 +129,10 @@ where } } -impl Clone for MapErrServiceFactory +impl Clone for MapErrServiceFactory where - A: ServiceFactory + Clone, - F: Fn(A::Error) -> E + Clone, + SF: ServiceFactory + Clone, + F: Fn(SF::Error) -> E + Clone, { fn clone(&self) -> Self { Self { @@ -144,57 +143,57 @@ where } } -impl ServiceFactory for MapErrServiceFactory +impl ServiceFactory for MapErrServiceFactory where - A: ServiceFactory, - F: Fn(A::Error) -> E + Clone, + SF: ServiceFactory, + F: Fn(SF::Error) -> E + Clone, { - type Response = A::Response; + type Response = SF::Response; type Error = E; - type Config = A::Config; - type Service = MapErr; - type InitError = A::InitError; - type Future = MapErrServiceFuture; + type Config = SF::Config; + type Service = MapErr; + type InitError = SF::InitError; + type Future = MapErrServiceFuture; - fn new_service(&self, cfg: A::Config) -> Self::Future { + fn new_service(&self, cfg: SF::Config) -> Self::Future { MapErrServiceFuture::new(self.a.new_service(cfg), self.f.clone()) } } pin_project! { - pub struct MapErrServiceFuture + pub struct MapErrServiceFuture where - A: ServiceFactory, - F: Fn(A::Error) -> E, + SF: ServiceFactory, + F: Fn(SF::Error) -> E, { #[pin] - fut: A::Future, - f: F, + fut: SF::Future, + mapper: F, } } -impl MapErrServiceFuture +impl MapErrServiceFuture where - A: ServiceFactory, - F: Fn(A::Error) -> E, + SF: ServiceFactory, + F: Fn(SF::Error) -> E, { - fn new(fut: A::Future, f: F) -> Self { - MapErrServiceFuture { fut, f } + fn new(fut: SF::Future, mapper: F) -> Self { + MapErrServiceFuture { fut, mapper } } } -impl Future for MapErrServiceFuture +impl Future for MapErrServiceFuture where - A: ServiceFactory, - F: Fn(A::Error) -> E + Clone, + SF: ServiceFactory, + F: Fn(SF::Error) -> E + Clone, { - type Output = Result, A::InitError>; + type Output = Result, SF::InitError>; fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { let this = self.project(); if let Poll::Ready(svc) = this.fut.poll(cx)? { - Poll::Ready(Ok(MapErr::new(svc, this.f.clone()))) + Poll::Ready(Ok(MapErr::new(svc, this.mapper.clone()))) } else { Poll::Pending }