diff options
Diffstat (limited to 'src/liballoc/boxed.rs')
| -rw-r--r-- | src/liballoc/boxed.rs | 57 |
1 files changed, 39 insertions, 18 deletions
diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index 6a05ef68088..fb16bdf0ab4 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -58,16 +58,16 @@ use core::any::Any; use core::borrow; use core::cmp::Ordering; +use core::convert::From; use core::fmt; -use core::future::Future; +use core::future::{Future, FutureObj, LocalFutureObj, UnsafeFutureObj}; use core::hash::{Hash, Hasher}; use core::iter::FusedIterator; use core::marker::{Unpin, Unsize}; use core::mem::{self, PinMut}; use core::ops::{CoerceUnsized, Deref, DerefMut, Generator, GeneratorState}; use core::ptr::{self, NonNull, Unique}; -use core::task::{Context, Poll, UnsafeTask, TaskObj, LocalTaskObj}; -use core::convert::From; +use core::task::{Context, Poll}; use raw_vec::RawVec; use str::from_boxed_utf8_unchecked; @@ -915,7 +915,7 @@ impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<PinBox<U>> for PinBox<T> {} impl<T: ?Sized> Unpin for PinBox<T> {} #[unstable(feature = "futures_api", issue = "50547")] -impl<'a, F: ?Sized + Future + Unpin> Future for Box<F> { +impl<F: ?Sized + Future + Unpin> Future for Box<F> { type Output = F::Output; fn poll(mut self: PinMut<Self>, cx: &mut Context) -> Poll<Self::Output> { @@ -924,7 +924,7 @@ impl<'a, F: ?Sized + Future + Unpin> Future for Box<F> { } #[unstable(feature = "futures_api", issue = "50547")] -impl<'a, F: ?Sized + Future> Future for PinBox<F> { +impl<F: ?Sized + Future> Future for PinBox<F> { type Output = F::Output; fn poll(mut self: PinMut<Self>, cx: &mut Context) -> Poll<Self::Output> { @@ -933,46 +933,67 @@ impl<'a, F: ?Sized + Future> Future for PinBox<F> { } #[unstable(feature = "futures_api", issue = "50547")] -unsafe impl<F: Future<Output = ()> + 'static> UnsafeTask for PinBox<F> { +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 +{ fn into_raw(self) -> *mut () { PinBox::into_raw(self) as *mut () } - unsafe fn poll(task: *mut (), cx: &mut Context) -> Poll<()> { - let ptr = task as *mut F; + 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(task: *mut ()) { - drop(PinBox::from_raw(task as *mut F)) + unsafe fn drop(ptr: *mut ()) { + drop(PinBox::from_raw(ptr as *mut F)) } } #[unstable(feature = "futures_api", issue = "50547")] -impl<F: Future<Output = ()> + Send + 'static> From<PinBox<F>> for TaskObj { +impl<'a, F: Future<Output = ()> + Send + 'a> From<PinBox<F>> for FutureObj<'a, ()> { fn from(boxed: PinBox<F>) -> Self { - TaskObj::new(boxed) + FutureObj::new(boxed) } } #[unstable(feature = "futures_api", issue = "50547")] -impl<F: Future<Output = ()> + Send + 'static> From<Box<F>> for TaskObj { +impl<'a, F: Future<Output = ()> + Send + 'a> From<Box<F>> for FutureObj<'a, ()> { fn from(boxed: Box<F>) -> Self { - TaskObj::new(PinBox::from(boxed)) + FutureObj::new(boxed) } } #[unstable(feature = "futures_api", issue = "50547")] -impl<F: Future<Output = ()> + 'static> From<PinBox<F>> for LocalTaskObj { +impl<'a, F: Future<Output = ()> + 'a> From<PinBox<F>> for LocalFutureObj<'a, ()> { fn from(boxed: PinBox<F>) -> Self { - LocalTaskObj::new(boxed) + LocalFutureObj::new(boxed) } } #[unstable(feature = "futures_api", issue = "50547")] -impl<F: Future<Output = ()> + 'static> From<Box<F>> for LocalTaskObj { +impl<'a, F: Future<Output = ()> + 'a> From<Box<F>> for LocalFutureObj<'a, ()> { fn from(boxed: Box<F>) -> Self { - LocalTaskObj::new(PinBox::from(boxed)) + LocalFutureObj::new(boxed) } } |
