Skip to content

Commit

Permalink
Added get_ref, get_mut and into_inner methods to Compat01As03 and Com…
Browse files Browse the repository at this point in the history
…pat01As03Sink
  • Loading branch information
VictorKoenders authored and cramertj committed Jul 7, 2019
1 parent f899af5 commit b9ba5d4
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 8 deletions.
22 changes: 22 additions & 0 deletions futures-util/src/compat/compat01as03.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ impl<T> Compat01As03<T> {
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)
Expand Down Expand Up @@ -206,6 +218,16 @@ impl<S, SinkItem> Compat01As03Sink<S, SinkItem> {
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")]
Expand Down
32 changes: 24 additions & 8 deletions futures-util/src/compat/compat03as01.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ pub struct CompatSink<T, Item> {
}

impl<T> Compat<T> {
/// Returns the inner item.
pub fn into_inner(self) -> T {
self.inner
}

/// Creates a new [`Compat`].
///
/// For types which implement appropriate futures `0.3`
Expand All @@ -68,22 +63,43 @@ impl<T> Compat<T> {
pub fn get_ref(&self) -> &T {
&self.inner
}
}

#[cfg(feature = "sink")]
impl<T, Item> CompatSink<T, Item> {
/// 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<T, Item> CompatSink<T, Item> {
/// Creates a new [`CompatSink`].
pub fn new(inner: T) -> Self {
CompatSink {
inner,
_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<T, E>(x: task03::Poll<Result<T, E>>)
Expand Down

0 comments on commit b9ba5d4

Please sign in to comment.