From 43168944220ed32dab83cb4f11f7b97abc5818d5 Mon Sep 17 00:00:00 2001 From: Bruce Guenter Date: Fri, 10 Jul 2020 08:47:39 -0600 Subject: [PATCH] Add get_ref functions to more service layers (#463) * Implement get_ref, get_mut, and into_inner for Retry * Implement get_ref, get_mut, and into_inner for Timeout --- tower/src/retry/mod.rs | 15 +++++++++++++++ tower/src/timeout/mod.rs | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/tower/src/retry/mod.rs b/tower/src/retry/mod.rs index e369dbb..bbbc64e 100644 --- a/tower/src/retry/mod.rs +++ b/tower/src/retry/mod.rs @@ -31,6 +31,21 @@ impl Retry { pub fn new(policy: P, service: S) -> Self { Retry { policy, service } } + + /// Get a reference to the inner service + pub fn get_ref(&self) -> &S { + &self.service + } + + /// Get a mutable reference to the inner service + pub fn get_mut(&mut self) -> &mut S { + &mut self.service + } + + /// Consume `self`, returning the inner service + pub fn into_inner(self) -> S { + self.service + } } impl Service for Retry diff --git a/tower/src/timeout/mod.rs b/tower/src/timeout/mod.rs index 1a3e04b..ac5ae93 100644 --- a/tower/src/timeout/mod.rs +++ b/tower/src/timeout/mod.rs @@ -28,6 +28,21 @@ impl Timeout { pub fn new(inner: T, timeout: Duration) -> Self { Timeout { inner, timeout } } + + /// Get a reference to the inner service + pub fn get_ref(&self) -> &T { + &self.inner + } + + /// Get a mutable reference to the inner service + pub fn get_mut(&mut self) -> &mut T { + &mut self.inner + } + + /// Consume `self`, returning the inner service + pub fn into_inner(self) -> T { + self.inner + } } impl Service for Timeout