diff options
| author | Josef Reinhard Brandl <mail@josefbrandl.de> | 2018-07-02 19:21:32 +0200 |
|---|---|---|
| committer | Josef Reinhard Brandl <mail@josefbrandl.de> | 2018-07-02 19:21:32 +0200 |
| commit | e666c2bd0742cbf88ff9fa26cfc194099a139589 (patch) | |
| tree | c9b6cf2958ba7e63dddb3e2b1de2be0890575197 /src | |
| parent | ae408947de1311f9673d0ae34028933cd191ac90 (diff) | |
| download | rust-e666c2bd0742cbf88ff9fa26cfc194099a139589.tar.gz rust-e666c2bd0742cbf88ff9fa26cfc194099a139589.zip | |
Implemented `UnsafeFutureObj` on `Box`
Diffstat (limited to 'src')
| -rw-r--r-- | src/liballoc/boxed.rs | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index fabeaa1c144..fb16bdf0ab4 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -933,6 +933,25 @@ impl<F: ?Sized + Future> Future for PinBox<F> { } #[unstable(feature = "futures_api", issue = "50547")] +unsafe impl<'a, T, F> UnsafeFutureObj<'a, T> for Box<F> + where F: Future<Output = T> + 'a +{ + fn into_raw(self) -> *mut () { + Box::into_raw(self) as *mut () + } + + unsafe fn poll(ptr: *mut (), cx: &mut Context) -> Poll<T> { + let ptr = ptr as *mut F; + let pin: PinMut<F> = PinMut::new_unchecked(&mut *ptr); + pin.poll(cx) + } + + unsafe fn drop(ptr: *mut ()) { + drop(Box::from_raw(ptr as *mut F)) + } +} + +#[unstable(feature = "futures_api", issue = "50547")] unsafe impl<'a, T, F> UnsafeFutureObj<'a, T> for PinBox<F> where F: Future<Output = T> + 'a { @@ -961,7 +980,7 @@ impl<'a, F: Future<Output = ()> + Send + 'a> From<PinBox<F>> for FutureObj<'a, ( #[unstable(feature = "futures_api", issue = "50547")] impl<'a, F: Future<Output = ()> + Send + 'a> From<Box<F>> for FutureObj<'a, ()> { fn from(boxed: Box<F>) -> Self { - FutureObj::new(PinBox::from(boxed)) + FutureObj::new(boxed) } } @@ -975,6 +994,6 @@ impl<'a, F: Future<Output = ()> + 'a> From<PinBox<F>> for LocalFutureObj<'a, ()> #[unstable(feature = "futures_api", issue = "50547")] impl<'a, F: Future<Output = ()> + 'a> From<Box<F>> for LocalFutureObj<'a, ()> { fn from(boxed: Box<F>) -> Self { - LocalFutureObj::new(PinBox::from(boxed)) + LocalFutureObj::new(boxed) } } |
