Skip to content

Commit 971d7ed

Browse files
committed
move PinBox into pin module and export through std
1 parent 13da951 commit 971d7ed

File tree

8 files changed

+233
-207
lines changed

8 files changed

+233
-207
lines changed

src/liballoc/boxed.rs

Lines changed: 0 additions & 202 deletions
Original file line numberDiff line numberDiff line change
@@ -759,166 +759,6 @@ impl<T> Generator for Box<T>
759759
}
760760
}
761761

762-
/// A pinned, heap allocated reference.
763-
#[unstable(feature = "pin", issue = "49150")]
764-
#[fundamental]
765-
#[repr(transparent)]
766-
pub struct PinBox<T: ?Sized> {
767-
inner: Box<T>,
768-
}
769-
770-
#[unstable(feature = "pin", issue = "49150")]
771-
impl<T> PinBox<T> {
772-
/// Allocate memory on the heap, move the data into it and pin it.
773-
#[unstable(feature = "pin", issue = "49150")]
774-
pub fn new(data: T) -> PinBox<T> {
775-
PinBox { inner: Box::new(data) }
776-
}
777-
}
778-
779-
#[unstable(feature = "pin", issue = "49150")]
780-
impl<T: ?Sized> PinBox<T> {
781-
/// Get a pinned reference to the data in this PinBox.
782-
#[inline]
783-
pub fn as_pin_mut<'a>(&'a mut self) -> PinMut<'a, T> {
784-
unsafe { PinMut::new_unchecked(&mut *self.inner) }
785-
}
786-
787-
/// Constructs a `PinBox` from a raw pointer.
788-
///
789-
/// After calling this function, the raw pointer is owned by the
790-
/// resulting `PinBox`. Specifically, the `PinBox` destructor will call
791-
/// the destructor of `T` and free the allocated memory. Since the
792-
/// way `PinBox` allocates and releases memory is unspecified, the
793-
/// only valid pointer to pass to this function is the one taken
794-
/// from another `PinBox` via the [`PinBox::into_raw`] function.
795-
///
796-
/// This function is unsafe because improper use may lead to
797-
/// memory problems. For example, a double-free may occur if the
798-
/// function is called twice on the same raw pointer.
799-
///
800-
/// [`PinBox::into_raw`]: struct.PinBox.html#method.into_raw
801-
///
802-
/// # Examples
803-
///
804-
/// ```
805-
/// #![feature(pin)]
806-
/// use std::boxed::PinBox;
807-
/// let x = PinBox::new(5);
808-
/// let ptr = PinBox::into_raw(x);
809-
/// let x = unsafe { PinBox::from_raw(ptr) };
810-
/// ```
811-
#[inline]
812-
pub unsafe fn from_raw(raw: *mut T) -> Self {
813-
PinBox { inner: Box::from_raw(raw) }
814-
}
815-
816-
/// Consumes the `PinBox`, returning the wrapped raw pointer.
817-
///
818-
/// After calling this function, the caller is responsible for the
819-
/// memory previously managed by the `PinBox`. In particular, the
820-
/// caller should properly destroy `T` and release the memory. The
821-
/// proper way to do so is to convert the raw pointer back into a
822-
/// `PinBox` with the [`PinBox::from_raw`] function.
823-
///
824-
/// Note: this is an associated function, which means that you have
825-
/// to call it as `PinBox::into_raw(b)` instead of `b.into_raw()`. This
826-
/// is so that there is no conflict with a method on the inner type.
827-
///
828-
/// [`PinBox::from_raw`]: struct.PinBox.html#method.from_raw
829-
///
830-
/// # Examples
831-
///
832-
/// ```
833-
/// #![feature(pin)]
834-
/// use std::boxed::PinBox;
835-
/// let x = PinBox::new(5);
836-
/// let ptr = PinBox::into_raw(x);
837-
/// ```
838-
#[inline]
839-
pub fn into_raw(b: PinBox<T>) -> *mut T {
840-
Box::into_raw(b.inner)
841-
}
842-
843-
/// Get a mutable reference to the data inside this PinBox.
844-
///
845-
/// This function is unsafe. Users must guarantee that the data is never
846-
/// moved out of this reference.
847-
#[inline]
848-
pub unsafe fn get_mut<'a>(this: &'a mut PinBox<T>) -> &'a mut T {
849-
&mut *this.inner
850-
}
851-
852-
/// Convert this PinBox into an unpinned Box.
853-
///
854-
/// This function is unsafe. Users must guarantee that the data is never
855-
/// moved out of the box.
856-
#[inline]
857-
pub unsafe fn unpin(this: PinBox<T>) -> Box<T> {
858-
this.inner
859-
}
860-
}
861-
862-
#[unstable(feature = "pin", issue = "49150")]
863-
impl<T: ?Sized> From<Box<T>> for PinBox<T> {
864-
fn from(boxed: Box<T>) -> PinBox<T> {
865-
PinBox { inner: boxed }
866-
}
867-
}
868-
869-
#[unstable(feature = "pin", issue = "49150")]
870-
impl<T: Unpin + ?Sized> From<PinBox<T>> for Box<T> {
871-
fn from(pinned: PinBox<T>) -> Box<T> {
872-
pinned.inner
873-
}
874-
}
875-
876-
#[unstable(feature = "pin", issue = "49150")]
877-
impl<T: ?Sized> Deref for PinBox<T> {
878-
type Target = T;
879-
880-
fn deref(&self) -> &T {
881-
&*self.inner
882-
}
883-
}
884-
885-
#[unstable(feature = "pin", issue = "49150")]
886-
impl<T: Unpin + ?Sized> DerefMut for PinBox<T> {
887-
fn deref_mut(&mut self) -> &mut T {
888-
&mut *self.inner
889-
}
890-
}
891-
892-
#[unstable(feature = "pin", issue = "49150")]
893-
impl<T: fmt::Display + ?Sized> fmt::Display for PinBox<T> {
894-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
895-
fmt::Display::fmt(&*self.inner, f)
896-
}
897-
}
898-
899-
#[unstable(feature = "pin", issue = "49150")]
900-
impl<T: fmt::Debug + ?Sized> fmt::Debug for PinBox<T> {
901-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
902-
fmt::Debug::fmt(&*self.inner, f)
903-
}
904-
}
905-
906-
#[unstable(feature = "pin", issue = "49150")]
907-
impl<T: ?Sized> fmt::Pointer for PinBox<T> {
908-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
909-
// It's not possible to extract the inner Uniq directly from the Box,
910-
// instead we cast it to a *const which aliases the Unique
911-
let ptr: *const T = &*self.inner;
912-
fmt::Pointer::fmt(&ptr, f)
913-
}
914-
}
915-
916-
#[unstable(feature = "pin", issue = "49150")]
917-
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<PinBox<U>> for PinBox<T> {}
918-
919-
#[unstable(feature = "pin", issue = "49150")]
920-
impl<T: ?Sized> Unpin for PinBox<T> {}
921-
922762
#[unstable(feature = "futures_api", issue = "50547")]
923763
impl<F: ?Sized + Future + Unpin> Future for Box<F> {
924764
type Output = F::Output;
@@ -928,15 +768,6 @@ impl<F: ?Sized + Future + Unpin> Future for Box<F> {
928768
}
929769
}
930770

931-
#[unstable(feature = "futures_api", issue = "50547")]
932-
impl<F: ?Sized + Future> Future for PinBox<F> {
933-
type Output = F::Output;
934-
935-
fn poll(mut self: PinMut<Self>, cx: &mut Context) -> Poll<Self::Output> {
936-
self.as_pin_mut().poll(cx)
937-
}
938-
}
939-
940771
#[unstable(feature = "futures_api", issue = "50547")]
941772
unsafe impl<'a, T, F> UnsafeFutureObj<'a, T> for Box<F>
942773
where F: Future<Output = T> + 'a
@@ -956,25 +787,6 @@ unsafe impl<'a, T, F> UnsafeFutureObj<'a, T> for Box<F>
956787
}
957788
}
958789

959-
#[unstable(feature = "futures_api", issue = "50547")]
960-
unsafe impl<'a, T, F> UnsafeFutureObj<'a, T> for PinBox<F>
961-
where F: Future<Output = T> + 'a
962-
{
963-
fn into_raw(self) -> *mut () {
964-
PinBox::into_raw(self) as *mut ()
965-
}
966-
967-
unsafe fn poll(ptr: *mut (), cx: &mut Context) -> Poll<T> {
968-
let ptr = ptr as *mut F;
969-
let pin: PinMut<F> = PinMut::new_unchecked(&mut *ptr);
970-
pin.poll(cx)
971-
}
972-
973-
unsafe fn drop(ptr: *mut ()) {
974-
drop(PinBox::from_raw(ptr as *mut F))
975-
}
976-
}
977-
978790
#[unstable(feature = "futures_api", issue = "50547")]
979791
impl<Sp> Spawn for Box<Sp>
980792
where Sp: Spawn + ?Sized
@@ -991,27 +803,13 @@ impl<Sp> Spawn for Box<Sp>
991803
}
992804
}
993805

994-
#[unstable(feature = "futures_api", issue = "50547")]
995-
impl<'a, F: Future<Output = ()> + Send + 'a> From<PinBox<F>> for FutureObj<'a, ()> {
996-
fn from(boxed: PinBox<F>) -> Self {
997-
FutureObj::new(boxed)
998-
}
999-
}
1000-
1001806
#[unstable(feature = "futures_api", issue = "50547")]
1002807
impl<'a, F: Future<Output = ()> + Send + 'a> From<Box<F>> for FutureObj<'a, ()> {
1003808
fn from(boxed: Box<F>) -> Self {
1004809
FutureObj::new(boxed)
1005810
}
1006811
}
1007812

1008-
#[unstable(feature = "futures_api", issue = "50547")]
1009-
impl<'a, F: Future<Output = ()> + 'a> From<PinBox<F>> for LocalFutureObj<'a, ()> {
1010-
fn from(boxed: PinBox<F>) -> Self {
1011-
LocalFutureObj::new(boxed)
1012-
}
1013-
}
1014-
1015813
#[unstable(feature = "futures_api", issue = "50547")]
1016814
impl<'a, F: Future<Output = ()> + 'a> From<Box<F>> for LocalFutureObj<'a, ()> {
1017815
fn from(boxed: Box<F>) -> Self {

src/liballoc/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ pub mod collections;
159159
pub mod sync;
160160
pub mod rc;
161161
pub mod raw_vec;
162+
pub mod pin;
162163
pub mod prelude;
163164
pub mod borrow;
164165
pub mod fmt;

0 commit comments

Comments
 (0)