Skip to content

Commit b9ba5d4

Browse files
VictorKoenderscramertj
authored andcommitted
Added get_ref, get_mut and into_inner methods to Compat01As03 and Compat01As03Sink
1 parent f899af5 commit b9ba5d4

File tree

2 files changed

+46
-8
lines changed

2 files changed

+46
-8
lines changed

futures-util/src/compat/compat01as03.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@ impl<T> Compat01As03<T> {
4646
pub fn get_ref(&self) -> &T {
4747
self.inner.get_ref()
4848
}
49+
50+
/// Get a mutable reference to 0.1 Future, Stream, AsyncRead or AsyncWrite object contained
51+
/// within.
52+
pub fn get_mut(&mut self) -> &mut T {
53+
self.inner.get_mut()
54+
}
55+
56+
/// Consume this wrapper to return the underlying 0.1 Future, Stream, AsyncRead, or
57+
/// AsyncWrite object.
58+
pub fn into_inner(self) -> T {
59+
self.inner.into_inner()
60+
}
4961
}
5062

5163
/// Extension trait for futures 0.1 [`Future`](futures_01::future::Future)
@@ -206,6 +218,16 @@ impl<S, SinkItem> Compat01As03Sink<S, SinkItem> {
206218
pub fn get_ref(&self) -> &S {
207219
self.inner.get_ref()
208220
}
221+
222+
/// Get a mutable reference to 0.1 Sink contained within.
223+
pub fn get_mut(&mut self) -> &mut S {
224+
self.inner.get_mut()
225+
}
226+
227+
/// Consume this wrapper to return the underlying 0.1 Sink.
228+
pub fn into_inner(self) -> S {
229+
self.inner.into_inner()
230+
}
209231
}
210232

211233
#[cfg(feature = "sink")]

futures-util/src/compat/compat03as01.rs

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,6 @@ pub struct CompatSink<T, Item> {
4949
}
5050

5151
impl<T> Compat<T> {
52-
/// Returns the inner item.
53-
pub fn into_inner(self) -> T {
54-
self.inner
55-
}
56-
5752
/// Creates a new [`Compat`].
5853
///
5954
/// For types which implement appropriate futures `0.3`
@@ -68,22 +63,43 @@ impl<T> Compat<T> {
6863
pub fn get_ref(&self) -> &T {
6964
&self.inner
7065
}
71-
}
7266

73-
#[cfg(feature = "sink")]
74-
impl<T, Item> CompatSink<T, Item> {
67+
/// Get a mutable reference to 0.3 Future, Stream, AsyncRead, or AsyncWrite object
68+
/// contained within.
69+
pub fn get_mut(&mut self) -> &mut T {
70+
&mut self.inner
71+
}
72+
7573
/// Returns the inner item.
7674
pub fn into_inner(self) -> T {
7775
self.inner
7876
}
77+
}
7978

79+
#[cfg(feature = "sink")]
80+
impl<T, Item> CompatSink<T, Item> {
8081
/// Creates a new [`CompatSink`].
8182
pub fn new(inner: T) -> Self {
8283
CompatSink {
8384
inner,
8485
_phantom: PhantomData,
8586
}
8687
}
88+
89+
/// Get a reference to 0.3 Sink contained within.
90+
pub fn get_ref(&self) -> &T {
91+
&self.inner
92+
}
93+
94+
/// Get a mutable reference to 0.3 Sink contained within.
95+
pub fn get_mut(&mut self) -> &mut T {
96+
&mut self.inner
97+
}
98+
99+
/// Returns the inner item.
100+
pub fn into_inner(self) -> T {
101+
self.inner
102+
}
87103
}
88104

89105
fn poll_03_to_01<T, E>(x: task03::Poll<Result<T, E>>)

0 commit comments

Comments
 (0)