Skip to content

Commit e666c2b

Browse files
Implemented UnsafeFutureObj on Box
1 parent ae40894 commit e666c2b

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/liballoc/boxed.rs

+21-2
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,25 @@ impl<F: ?Sized + Future> Future for PinBox<F> {
932932
}
933933
}
934934

935+
#[unstable(feature = "futures_api", issue = "50547")]
936+
unsafe impl<'a, T, F> UnsafeFutureObj<'a, T> for Box<F>
937+
where F: Future<Output = T> + 'a
938+
{
939+
fn into_raw(self) -> *mut () {
940+
Box::into_raw(self) as *mut ()
941+
}
942+
943+
unsafe fn poll(ptr: *mut (), cx: &mut Context) -> Poll<T> {
944+
let ptr = ptr as *mut F;
945+
let pin: PinMut<F> = PinMut::new_unchecked(&mut *ptr);
946+
pin.poll(cx)
947+
}
948+
949+
unsafe fn drop(ptr: *mut ()) {
950+
drop(Box::from_raw(ptr as *mut F))
951+
}
952+
}
953+
935954
#[unstable(feature = "futures_api", issue = "50547")]
936955
unsafe impl<'a, T, F> UnsafeFutureObj<'a, T> for PinBox<F>
937956
where F: Future<Output = T> + 'a
@@ -961,7 +980,7 @@ impl<'a, F: Future<Output = ()> + Send + 'a> From<PinBox<F>> for FutureObj<'a, (
961980
#[unstable(feature = "futures_api", issue = "50547")]
962981
impl<'a, F: Future<Output = ()> + Send + 'a> From<Box<F>> for FutureObj<'a, ()> {
963982
fn from(boxed: Box<F>) -> Self {
964-
FutureObj::new(PinBox::from(boxed))
983+
FutureObj::new(boxed)
965984
}
966985
}
967986

@@ -975,6 +994,6 @@ impl<'a, F: Future<Output = ()> + 'a> From<PinBox<F>> for LocalFutureObj<'a, ()>
975994
#[unstable(feature = "futures_api", issue = "50547")]
976995
impl<'a, F: Future<Output = ()> + 'a> From<Box<F>> for LocalFutureObj<'a, ()> {
977996
fn from(boxed: Box<F>) -> Self {
978-
LocalFutureObj::new(PinBox::from(boxed))
997+
LocalFutureObj::new(boxed)
979998
}
980999
}

0 commit comments

Comments
 (0)