Skip to content

Commit 766353c

Browse files
committed
futures 0.1 extension trait
1 parent a15185d commit 766353c

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

futures-util/src/compat/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,16 @@ impl Wake for Current {
133133
arc_self.0.notify();
134134
}
135135
}
136+
137+
/// Extension trait for futures 0.1.
138+
pub trait Future01Ext: Future01 {
139+
/// Converts the future into a futures 0.3 future.
140+
fn compat(self) -> Compat<Self, ()> where Self: Sized {
141+
Compat {
142+
inner: self,
143+
executor: None,
144+
}
145+
}
146+
}
147+
148+
impl<T: Future01> Future01Ext for T {}

futures-util/src/future/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ mod chain;
6868
crate use self::chain::Chain;
6969

7070
if_std! {
71+
use std::boxed::PinBox;
72+
7173
mod abortable;
7274
pub use self::abortable::{abortable, Abortable, AbortHandle, AbortRegistration, Aborted};
7375

@@ -86,8 +88,6 @@ if_std! {
8688

8789
mod shared;
8890
pub use self::shared::Shared;
89-
90-
use std::boxed::PinBox;
9191
}
9292

9393
impl<T: ?Sized> FutureExt for T where T: Future {}

futures-util/src/future/never_error.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ impl<Fut, T> Future for NeverError<Fut>
2929
type Output = Result<T, ()>;
3030

3131
fn poll(mut self: PinMut<Self>, cx: &mut task::Context) -> Poll<Result<T, ()>> {
32-
match self.future().poll(cx) {
33-
Poll::Pending => Poll::Pending,
34-
Poll::Ready(output) => {
35-
Poll::Ready(Ok(output))
36-
}
37-
}
32+
self.future().poll(cx).map(Ok)
3833
}
3934
}

0 commit comments

Comments
 (0)