Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compat wrapper methods #1705

Merged
merged 1 commit into from
Jul 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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