From faf36f5c04190659ee9403a84919d62b17bf86b2 Mon Sep 17 00:00:00 2001 From: Jane Lusby Date: Wed, 17 Jun 2020 17:00:19 -0700 Subject: [PATCH] require clone bound inner error type rather than Arcifying it ourselves --- tower-batch/src/layer.rs | 2 +- tower-batch/src/service.rs | 6 +++--- tower-batch/src/worker.rs | 25 +++++++++++++++---------- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/tower-batch/src/layer.rs b/tower-batch/src/layer.rs index a7631ac5..187b6f5c 100644 --- a/tower-batch/src/layer.rs +++ b/tower-batch/src/layer.rs @@ -40,7 +40,7 @@ where S::Future: Send, S::Error: Clone + Into + Send + Sync, Request: Send + 'static, - E: Clone + Send + 'static, + E: Send + 'static, crate::error::Closed: Into, { type Service = Batch; diff --git a/tower-batch/src/service.rs b/tower-batch/src/service.rs index cba07b60..1454fad6 100644 --- a/tower-batch/src/service.rs +++ b/tower-batch/src/service.rs @@ -22,14 +22,14 @@ where T: Service>, { tx: mpsc::Sender>, - handle: Handle, + handle: Handle, _error_type: PhantomData, } impl Batch where T: Service>, - T::Error: Into, + T::Error: Into + Clone, E: Send + 'static, crate::error::Closed: Into, // crate::error::Closed: Into<>::Error> + Send + Sync + 'static, @@ -72,7 +72,7 @@ impl Service for Batch where T: Service>, crate::error::Closed: Into, - T::Error: Into, + T::Error: Into + Clone, E: Send + 'static, { type Response = T::Response; diff --git a/tower-batch/src/worker.rs b/tower-batch/src/worker.rs index 8b314ed7..6fdcf4f4 100644 --- a/tower-batch/src/worker.rs +++ b/tower-batch/src/worker.rs @@ -34,7 +34,7 @@ where rx: mpsc::Receiver>, service: T, failed: Option, - handle: Handle, + handle: Handle, max_items: usize, max_latency: std::time::Duration, _error_type: PhantomData, @@ -42,8 +42,9 @@ where /// Get the error out #[derive(Debug)] -pub(crate) struct Handle { +pub(crate) struct Handle { inner: Arc>>, + _e: PhantomData, } impl Worker @@ -56,9 +57,10 @@ where rx: mpsc::Receiver>, max_items: usize, max_latency: std::time::Duration, - ) -> (Handle, Worker) { + ) -> (Handle, Worker) { let handle = Handle { inner: Arc::new(Mutex::new(None)), + _e: PhantomData, }; let worker = Worker { @@ -190,7 +192,7 @@ where return; } - *inner = Some(error.clone().into()); + *inner = Some(error.clone()); drop(inner); self.rx.close(); @@ -203,23 +205,26 @@ where } } -impl Handle +impl Handle where - crate::error::Closed: Into, + E: Clone + Into, + crate::error::Closed: Into, { - pub(crate) fn get_error_on_closed(&self) -> E { + pub(crate) fn get_error_on_closed(&self) -> E2 { self.inner .lock() .unwrap() - .take() + .clone() + .map(Into::into) .unwrap_or_else(|| Closed::new().into()) } } -impl Clone for Handle { - fn clone(&self) -> Handle { +impl Clone for Handle { + fn clone(&self) -> Handle { Handle { inner: self.inner.clone(), + _e: PhantomData, } } }