mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-17 05:25:37 +03:00
Implemented UnsafeFutureObj on Box
This commit is contained in:
+21
-2
@@ -932,6 +932,25 @@ fn poll(mut self: PinMut<Self>, cx: &mut Context) -> Poll<Self::Output> {
|
||||
}
|
||||
}
|
||||
|
||||
#[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 @@ fn from(boxed: PinBox<F>) -> Self {
|
||||
#[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 @@ fn from(boxed: PinBox<F>) -> Self {
|
||||
#[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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user