diff options
| author | tinaun <tinagma@gmail.com> | 2018-06-08 16:45:27 -0400 |
|---|---|---|
| committer | tinaun <tinagma@gmail.com> | 2018-06-08 17:56:59 -0400 |
| commit | 6e5c18e8dc94a679126d276884a3ad4b9a3e0934 (patch) | |
| tree | c7b916bf935b8d4bf1d7d9646b13b71e76157006 /src/libcore | |
| parent | 1b4c921103ff4ae225f2d84a8b13f1616dcb538e (diff) | |
| download | rust-6e5c18e8dc94a679126d276884a3ad4b9a3e0934.tar.gz rust-6e5c18e8dc94a679126d276884a3ad4b9a3e0934.zip | |
add a few blanket future impls to std
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/future.rs | 17 | ||||
| -rw-r--r-- | src/libcore/task.rs | 6 |
2 files changed, 23 insertions, 0 deletions
diff --git a/src/libcore/future.rs b/src/libcore/future.rs index b4d087f8edb..a8c8f69411e 100644 --- a/src/libcore/future.rs +++ b/src/libcore/future.rs @@ -15,6 +15,7 @@ //! Asynchronous values. use mem::PinMut; +use marker::Unpin; use task::{self, Poll}; /// A future represents an asychronous computation. @@ -91,3 +92,19 @@ pub trait Future { /// about the behavior of `poll` after a future has completed. fn poll(self: PinMut<Self>, cx: &mut task::Context) -> Poll<Self::Output>; } + +impl<'a, F: ?Sized + Future + Unpin> Future for &'a mut F { + type Output = F::Output; + + fn poll(mut self: PinMut<Self>, cx: &mut task::Context) -> Poll<Self::Output> { + F::poll(PinMut::new(&mut **self), cx) + } +} + +impl<'a, F: ?Sized + Future> Future for PinMut<'a, F> { + type Output = F::Output; + + fn poll(mut self: PinMut<Self>, cx: &mut task::Context) -> Poll<Self::Output> { + F::poll((*self).reborrow(), cx) + } +} diff --git a/src/libcore/task.rs b/src/libcore/task.rs index e46a6d41d7a..ab1c1da5790 100644 --- a/src/libcore/task.rs +++ b/src/libcore/task.rs @@ -32,6 +32,12 @@ pub enum Poll<T> { Pending, } +impl<T> From<T> for Poll<T> { + fn from(t: T) -> Poll<T> { + Poll::Ready(t) + } +} + /// A `Waker` is a handle for waking up a task by notifying its executor that it /// is ready to be run. /// |
