1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
use core::ops::{CoerceUnsized, Deref, DerefMut};
use core::marker::Unsize;
use Unpin;
use Pin;
use PinMut;
#[fundamental]
pub struct PinBox<T: ?Sized> {
inner: Box<T>
}
impl<T> PinBox<T> {
pub fn new(data: T) -> PinBox<T> {
PinBox { inner: Box::new(data) }
}
pub unsafe fn into_inner_unchecked(self) -> T {
*self.inner
}
}
impl<T: ?Sized> PinBox<T> {
pub fn as_pin<'a>(&'a self) -> Pin<'a, T> {
unsafe { Pin::new_unchecked(&*self.inner) }
}
pub fn as_pin_mut<'a>(&'a mut self) -> PinMut<'a, T> {
unsafe { PinMut::new_unchecked(&mut*self.inner) }
}
pub unsafe fn into_box_unchecked(self) -> Box<T> {
self.inner
}
}
impl<T: Unpin> PinBox<T> {
pub fn into_inner(self) -> T {
*self.inner
}
}
impl<T: Unpin + ?Sized> PinBox<T> {
pub fn into_box(self) -> Box<T> {
self.inner
}
}
impl<T: Unpin + ?Sized> Deref for PinBox<T> {
type Target = T;
fn deref(&self) -> &T {
&*self.inner
}
}
impl<T: Unpin + ?Sized> DerefMut for PinBox<T> {
fn deref_mut(&mut self) -> &mut T {
&mut *self.inner
}
}
impl<T: ?Sized> From<Box<T>> for PinBox<T> {
fn from(boxed: Box<T>) -> PinBox<T> {
PinBox { inner: boxed }
}
}
unsafe impl<T: ?Sized> Unpin for PinBox<T> { }
impl<T, U> CoerceUnsized<PinBox<U>> for PinBox<T> where
T: Unsize<U> + ?Sized,
U: ?Sized,
{ }