Skip to content

Commit

Permalink
Update to a new pinning API.
Browse files Browse the repository at this point in the history
  • Loading branch information
Without Boats committed Sep 1, 2018
1 parent e6b35b0 commit 974bdc8
Show file tree
Hide file tree
Showing 14 changed files with 309 additions and 420 deletions.
38 changes: 28 additions & 10 deletions src/liballoc/boxed.rs
Expand Up @@ -65,13 +65,12 @@ use core::hash::{Hash, Hasher};
use core::iter::FusedIterator;
use core::marker::{Unpin, Unsize};
use core::mem;
use core::pin::PinMut;
use core::pin::Pin;
use core::ops::{CoerceUnsized, Deref, DerefMut, Generator, GeneratorState};
use core::ptr::{self, NonNull, Unique};
use core::task::{Context, Poll, Spawn, SpawnErrorKind, SpawnObjError};

use raw_vec::RawVec;
use pin::PinBox;
use str::from_boxed_utf8_unchecked;

/// A pointer type for heap allocation.
Expand All @@ -97,6 +96,11 @@ impl<T> Box<T> {
pub fn new(x: T) -> Box<T> {
box x
}

#[unstable(feature = "pin", issue = "49150")]
pub fn pinned(x: T) -> Pin<Box<T>> {
unsafe { Pin::new_unchecked(box x) }
}
}

impl<T: ?Sized> Box<T> {
Expand Down Expand Up @@ -427,6 +431,13 @@ impl<T> From<T> for Box<T> {
}
}

#[unstable(feature = "pin", issue = "49150")]
impl<T> From<Box<T>> for Pin<Box<T>> {
fn from(boxed: Box<T>) -> Self {
unsafe { Pin::new_unchecked(boxed) }
}
}

#[stable(feature = "box_from_slice", since = "1.17.0")]
impl<'a, T: Copy> From<&'a [T]> for Box<[T]> {
fn from(slice: &'a [T]) -> Box<[T]> {
Expand Down Expand Up @@ -764,8 +775,8 @@ impl<T> Generator for Box<T>
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> {
PinMut::new(&mut **self).poll(cx)
fn poll(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
F::poll(Pin::new(&mut *self), cx)
}
}

Expand All @@ -779,8 +790,8 @@ unsafe impl<'a, T, F> UnsafeFutureObj<'a, T> for Box<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)
let pin: Pin<&mut F> = Pin::new_unchecked(&mut *ptr);
F::poll(pin, cx)
}

unsafe fn drop(ptr: *mut ()) {
Expand Down Expand Up @@ -818,9 +829,16 @@ impl<'a, F: Future<Output = ()> + 'a> From<Box<F>> for LocalFutureObj<'a, ()> {
}
}

#[unstable(feature = "pin", issue = "49150")]
impl<T: Unpin + ?Sized> From<PinBox<T>> for Box<T> {
fn from(pinned: PinBox<T>) -> Box<T> {
unsafe { PinBox::unpin(pinned) }
#[unstable(feature = "futures_api", issue = "50547")]
impl<'a, F: Future<Output = ()> + Send + 'a> From<Pin<Box<F>>> for FutureObj<'a, ()> {
fn from(boxed: Pin<Box<F>>) -> Self {
FutureObj::new(boxed)
}
}

#[unstable(feature = "futures_api", issue = "50547")]
impl<'a, F: Future<Output = ()> + 'a> From<Pin<Box<F>>> for LocalFutureObj<'a, ()> {
fn from(boxed: Pin<Box<F>>) -> Self {
LocalFutureObj::new(boxed)
}
}
1 change: 0 additions & 1 deletion src/liballoc/lib.rs
Expand Up @@ -160,7 +160,6 @@ pub mod collections;
pub mod sync;
pub mod rc;
pub mod raw_vec;
pub mod pin;
pub mod prelude;
pub mod borrow;
pub mod fmt;
Expand Down
302 changes: 0 additions & 302 deletions src/liballoc/pin.rs

This file was deleted.

0 comments on commit 974bdc8

Please sign in to comment.