diff options
| author | Josef Reinhard Brandl <mail@josefbrandl.de> | 2018-07-02 19:07:59 +0200 |
|---|---|---|
| committer | Josef Reinhard Brandl <mail@josefbrandl.de> | 2018-07-02 19:07:59 +0200 |
| commit | ae408947de1311f9673d0ae34028933cd191ac90 (patch) | |
| tree | 7c154be8dce7c95cb96d68d79040e96c5d1f4317 /src/libcore/future | |
| parent | 5fde8b92372f02deaf5c7fb638447a60112f9015 (diff) | |
| download | rust-ae408947de1311f9673d0ae34028933cd191ac90.tar.gz rust-ae408947de1311f9673d0ae34028933cd191ac90.zip | |
Implement `UnsafeFutureObj` for `&mut Future`
Diffstat (limited to 'src/libcore/future')
| -rw-r--r-- | src/libcore/future/future_obj.rs | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/libcore/future/future_obj.rs b/src/libcore/future/future_obj.rs index 99f21272538..98c504a3f7b 100644 --- a/src/libcore/future/future_obj.rs +++ b/src/libcore/future/future_obj.rs @@ -14,7 +14,7 @@ use fmt; use future::Future; -use marker::PhantomData; +use marker::{PhantomData, Unpin}; use mem::PinMut; use task::{Context, Poll}; @@ -163,3 +163,17 @@ pub unsafe trait UnsafeFutureObj<'a, T>: 'a { /// other calls to `drop` or `poll`. unsafe fn drop(ptr: *mut ()); } + +unsafe impl<'a, T, F> UnsafeFutureObj<'a, T> for &'a mut F + where F: Future<Output = T> + Unpin + 'a +{ + fn into_raw(self) -> *mut () { + self as *mut F as *mut () + } + + unsafe fn poll(ptr: *mut (), cx: &mut Context) -> Poll<T> { + PinMut::new_unchecked(&mut *(ptr as *mut F)).poll(cx) + } + + unsafe fn drop(_ptr: *mut ()) {} +} |
