Skip to content

Commit

Permalink
futures 0.1 extension trait
Browse files Browse the repository at this point in the history
  • Loading branch information
tinaun committed Jul 31, 2018
1 parent c2cde40 commit 404d3d0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
13 changes: 13 additions & 0 deletions futures-util/src/compat/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,16 @@ impl Wake for Current {
arc_self.0.notify();
}
}

/// Extension trait for futures 0.1.
pub trait Future01Ext: Future01 {
/// Converts the future into a futures 0.3 future.
fn compat(self) -> Compat<Self, ()> where Self: Sized {
Compat {
inner: self,
executor: None,
}
}
}

impl<T: Future01> Future01Ext for T {}
4 changes: 2 additions & 2 deletions futures-util/src/future/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ mod chain;
crate use self::chain::Chain;

if_std! {
use std::boxed::PinBox;

mod abortable;
pub use self::abortable::{abortable, Abortable, AbortHandle, AbortRegistration, Aborted};

Expand All @@ -86,8 +88,6 @@ if_std! {

mod shared;
pub use self::shared::Shared;

use std::boxed::PinBox;
}

impl<T: ?Sized> FutureExt for T where T: Future {}
Expand Down
7 changes: 1 addition & 6 deletions futures-util/src/future/never_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ impl<Fut, T> Future for NeverError<Fut>
type Output = Result<T, ()>;

fn poll(mut self: PinMut<Self>, cx: &mut task::Context) -> Poll<Result<T, ()>> {
match self.future().poll(cx) {
Poll::Pending => Poll::Pending,
Poll::Ready(output) => {
Poll::Ready(Ok(output))
}
}
self.future().poll(cx).map(Ok)
}
}

0 comments on commit 404d3d0

Please sign in to comment.