@@ -65,13 +65,12 @@ use core::hash::{Hash, Hasher};
65
65
use core:: iter:: FusedIterator ;
66
66
use core:: marker:: { Unpin , Unsize } ;
67
67
use core:: mem;
68
- use core:: pin:: PinMut ;
68
+ use core:: pin:: Pin ;
69
69
use core:: ops:: { CoerceUnsized , Deref , DerefMut , Generator , GeneratorState } ;
70
70
use core:: ptr:: { self , NonNull , Unique } ;
71
71
use core:: task:: { Context , Poll , Spawn , SpawnErrorKind , SpawnObjError } ;
72
72
73
73
use raw_vec:: RawVec ;
74
- use pin:: PinBox ;
75
74
use str:: from_boxed_utf8_unchecked;
76
75
77
76
/// A pointer type for heap allocation.
@@ -97,6 +96,11 @@ impl<T> Box<T> {
97
96
pub fn new ( x : T ) -> Box < T > {
98
97
box x
99
98
}
99
+
100
+ #[ unstable( feature = "pin" , issue = "49150" ) ]
101
+ pub fn pinned ( x : T ) -> Pin < Box < T > > {
102
+ unsafe { Pin :: new_unchecked ( box x) }
103
+ }
100
104
}
101
105
102
106
impl < T : ?Sized > Box < T > {
@@ -427,6 +431,13 @@ impl<T> From<T> for Box<T> {
427
431
}
428
432
}
429
433
434
+ #[ unstable( feature = "pin" , issue = "49150" ) ]
435
+ impl < T > From < Box < T > > for Pin < Box < T > > {
436
+ fn from ( boxed : Box < T > ) -> Self {
437
+ unsafe { Pin :: new_unchecked ( boxed) }
438
+ }
439
+ }
440
+
430
441
#[ stable( feature = "box_from_slice" , since = "1.17.0" ) ]
431
442
impl < ' a , T : Copy > From < & ' a [ T ] > for Box < [ T ] > {
432
443
fn from ( slice : & ' a [ T ] ) -> Box < [ T ] > {
@@ -764,8 +775,8 @@ impl<T> Generator for Box<T>
764
775
impl < F : ?Sized + Future + Unpin > Future for Box < F > {
765
776
type Output = F :: Output ;
766
777
767
- fn poll ( mut self : PinMut < Self > , cx : & mut Context ) -> Poll < Self :: Output > {
768
- PinMut :: new ( & mut * * self ) . poll ( cx)
778
+ fn poll ( mut self : Pin < & mut Self > , cx : & mut Context ) -> Poll < Self :: Output > {
779
+ F :: poll ( Pin :: new ( & mut * self ) , cx)
769
780
}
770
781
}
771
782
@@ -779,8 +790,8 @@ unsafe impl<'a, T, F> UnsafeFutureObj<'a, T> for Box<F>
779
790
780
791
unsafe fn poll ( ptr : * mut ( ) , cx : & mut Context ) -> Poll < T > {
781
792
let ptr = ptr as * mut F ;
782
- let pin: PinMut < F > = PinMut :: new_unchecked ( & mut * ptr) ;
783
- pin . poll ( cx)
793
+ let pin: Pin < & mut F > = Pin :: new_unchecked ( & mut * ptr) ;
794
+ F :: poll ( pin , cx)
784
795
}
785
796
786
797
unsafe fn drop ( ptr : * mut ( ) ) {
@@ -818,9 +829,16 @@ impl<'a, F: Future<Output = ()> + 'a> From<Box<F>> for LocalFutureObj<'a, ()> {
818
829
}
819
830
}
820
831
821
- #[ unstable( feature = "pin" , issue = "49150" ) ]
822
- impl < T : Unpin + ?Sized > From < PinBox < T > > for Box < T > {
823
- fn from ( pinned : PinBox < T > ) -> Box < T > {
824
- unsafe { PinBox :: unpin ( pinned) }
832
+ #[ unstable( feature = "futures_api" , issue = "50547" ) ]
833
+ impl < ' a , F : Future < Output = ( ) > + Send + ' a > From < Pin < Box < F > > > for FutureObj < ' a , ( ) > {
834
+ fn from ( boxed : Pin < Box < F > > ) -> Self {
835
+ FutureObj :: new ( boxed)
836
+ }
837
+ }
838
+
839
+ #[ unstable( feature = "futures_api" , issue = "50547" ) ]
840
+ impl < ' a , F : Future < Output = ( ) > + ' a > From < Pin < Box < F > > > for LocalFutureObj < ' a , ( ) > {
841
+ fn from ( boxed : Pin < Box < F > > ) -> Self {
842
+ LocalFutureObj :: new ( boxed)
825
843
}
826
844
}
0 commit comments