chore: reduce pin related unsafe code (#2613)

This commit is contained in:
Taiki Endo
2020-06-12 19:49:39 +09:00
committed by GitHub
parent 68b4ca9f55
commit 6b6e76080a
6 changed files with 48 additions and 58 deletions
+2 -12
View File
@@ -46,21 +46,11 @@ const SLEEP: usize = 2;
impl<T> Spawn<T> {
/// Consumes `self` returning the inner value
pub fn into_inner(mut self) -> T
pub fn into_inner(self) -> T
where
T: Unpin,
{
drop(self.task);
// Pin::into_inner is unstable, so we work around it
//
// Safety: `T` is bound by `Unpin`.
unsafe {
let ptr = Pin::get_mut(self.future.as_mut()) as *mut T;
let future = Box::from_raw(ptr);
mem::forget(self.future);
*future
}
*Pin::into_inner(self.future)
}
/// Returns `true` if the inner future has received a wake notification