From d3e1aa9b42dcbbac508db8f1bf7c4b983a422b6a Mon Sep 17 00:00:00 2001 From: Trangar Date: Tue, 2 Jul 2019 09:15:50 +0200 Subject: [PATCH] Added get_ref, get_mut and into_inner methods to Compat01As03 and Compat01As03Sink --- futures-util/src/compat/compat01as03.rs | 22 +++++++++++++++++ futures-util/src/compat/compat03as01.rs | 32 ++++++++++++++++++------- 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/futures-util/src/compat/compat01as03.rs b/futures-util/src/compat/compat01as03.rs index 2f7d251099..24837ba6e6 100644 --- a/futures-util/src/compat/compat01as03.rs +++ b/futures-util/src/compat/compat01as03.rs @@ -46,6 +46,18 @@ impl Compat01As03 { pub fn get_ref(&self) -> &T { self.inner.get_ref() } + + /// Get a mutable reference to 0.1 Future, Stream, AsyncRead or AsyncWrite object contained + /// within. + pub fn get_mut(&mut self) -> &mut T { + self.inner.get_mut() + } + + /// Consume this wrapper to return the underlying 0.1 Future, Stream, AsyncRead, or + /// AsyncWrite object. + pub fn into_inner(self) -> T { + self.inner.into_inner() + } } /// Extension trait for futures 0.1 [`Future`](futures_01::future::Future) @@ -206,6 +218,16 @@ impl Compat01As03Sink { pub fn get_ref(&self) -> &S { self.inner.get_ref() } + + /// Get a mutable reference to 0.1 Sink contained within. + pub fn get_mut(&mut self) -> &mut S { + self.inner.get_mut() + } + + /// Consume this wrapper to return the underlying 0.1 Sink. + pub fn into_inner(self) -> S { + self.inner.into_inner() + } } #[cfg(feature = "sink")] diff --git a/futures-util/src/compat/compat03as01.rs b/futures-util/src/compat/compat03as01.rs index fd999d0b3e..44b21bbaff 100644 --- a/futures-util/src/compat/compat03as01.rs +++ b/futures-util/src/compat/compat03as01.rs @@ -49,11 +49,6 @@ pub struct CompatSink { } impl Compat { - /// Returns the inner item. - pub fn into_inner(self) -> T { - self.inner - } - /// Creates a new [`Compat`]. /// /// For types which implement appropriate futures `0.3` @@ -68,15 +63,21 @@ impl Compat { pub fn get_ref(&self) -> &T { &self.inner } -} -#[cfg(feature = "sink")] -impl CompatSink { + /// Get a mutable reference to 0.3 Future, Stream, AsyncRead, or AsyncWrite object + /// contained within. + pub fn get_mut(&mut self) -> &mut T { + &mut self.inner + } + /// Returns the inner item. pub fn into_inner(self) -> T { self.inner } +} +#[cfg(feature = "sink")] +impl CompatSink { /// Creates a new [`CompatSink`]. pub fn new(inner: T) -> Self { CompatSink { @@ -84,6 +85,21 @@ impl CompatSink { _phantom: PhantomData, } } + + /// Get a reference to 0.3 Sink contained within. + pub fn get_ref(&self) -> &T { + &self.inner + } + + /// Get a mutable reference to 0.3 Sink contained within. + pub fn get_mut(&mut self) -> &mut T { + &mut self.inner + } + + /// Returns the inner item. + pub fn into_inner(self) -> T { + self.inner + } } fn poll_03_to_01(x: task03::Poll>)