From 5b74c79cf9430ba02fb07befd618b30987cb23b8 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Tue, 19 Nov 2019 06:51:43 +0600 Subject: [PATCH] Simplify transform trait, remove map_init_err --- actix-service/src/lib.rs | 2 +- actix-service/src/transform.rs | 99 ---------------------------------- 2 files changed, 1 insertion(+), 100 deletions(-) diff --git a/actix-service/src/lib.rs b/actix-service/src/lib.rs index 141d25b0..96bbf5b8 100644 --- a/actix-service/src/lib.rs +++ b/actix-service/src/lib.rs @@ -298,5 +298,5 @@ pub mod dev { pub use crate::map_err::{MapErr, MapErrServiceFactory}; pub use crate::map_init_err::MapInitErr; pub use crate::then::{ThenService, ThenServiceFactory}; - pub use crate::transform::{ApplyTransform, TransformMapInitErr}; + pub use crate::transform::ApplyTransform; } diff --git a/actix-service/src/transform.rs b/actix-service/src/transform.rs index d57a6296..2b22b25f 100644 --- a/actix-service/src/transform.rs +++ b/actix-service/src/transform.rs @@ -1,5 +1,4 @@ use std::future::Future; -use std::marker::PhantomData; use std::pin::Pin; use std::rc::Rc; use std::sync::Arc; @@ -37,17 +36,6 @@ pub trait Transform { /// Creates and returns a new Service component, asynchronously fn new_transform(&self, service: S) -> Self::Future; - - /// Map this service's factory error to a different error, - /// returning a new transform service factory. - fn map_init_err(self, f: F) -> TransformMapInitErr - where - Self: Sized, - Self::Future: Unpin, - F: Fn(Self::InitError) -> E + Unpin + Clone, - { - TransformMapInitErr::new(self, f) - } } impl Transform for Rc @@ -187,90 +175,3 @@ where } } } - -/// Transform for the `map_err` combinator, changing the type of a new -/// transform's init error. -/// -/// This is created by the `Transform::map_err` method. -pub struct TransformMapInitErr { - t: T, - f: F, - e: PhantomData<(S, E)>, -} - -impl TransformMapInitErr { - /// Create new `TransformMapErr` new transform instance - pub(crate) fn new(t: T, f: F) -> Self - where - T: Transform, - T::Future: Unpin, - F: Fn(T::InitError) -> E + Unpin + Clone, - { - Self { - t, - f, - e: PhantomData, - } - } -} - -impl Clone for TransformMapInitErr -where - T: Clone, - F: Clone, -{ - fn clone(&self) -> Self { - Self { - t: self.t.clone(), - f: self.f.clone(), - e: PhantomData, - } - } -} - -impl Transform for TransformMapInitErr -where - T: Transform, - T::Future: Unpin, - F: Fn(T::InitError) -> E + Unpin + Clone, -{ - type Request = T::Request; - type Response = T::Response; - type Error = T::Error; - type Transform = T::Transform; - - type InitError = E; - type Future = TransformMapInitErrFuture; - - fn new_transform(&self, service: S) -> Self::Future { - TransformMapInitErrFuture { - fut: self.t.new_transform(service), - f: self.f.clone(), - } - } -} - -pub struct TransformMapInitErrFuture -where - T: Transform, - T::Future: Unpin, - F: Fn(T::InitError) -> E + Unpin, -{ - fut: T::Future, - f: F, -} - -impl Future for TransformMapInitErrFuture -where - T: Transform, - T::Future: Unpin, - F: Fn(T::InitError) -> E + Unpin + Clone, -{ - type Output = Result; - - fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - let this = self.get_mut(); - - Pin::new(&mut this.fut).poll(cx).map_err(&this.f) - } -}