Skip to content

Commit afcaba9

Browse files
committed
Implement TryFrom<Pin<$Rc<T>>> for Pin<$RcBox<T>>
This allows to construct a pinned rc-box from a pinned rc.
1 parent a1bc159 commit afcaba9

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

crates/rc-box/src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,19 @@ macro_rules! rc_box {
8484
}
8585
}
8686

87+
impl<T: ?Sized> TryFrom<Pin<$Rc<T>>> for Pin<$RcBox<T>> {
88+
type Error = Pin<$Rc<T>>;
89+
fn try_from(v: Pin<$Rc<T>>) -> Result<Pin<$RcBox<T>>, Pin<$Rc<T>>> {
90+
unsafe {
91+
let v = Pin::into_inner_unchecked(v);
92+
match $RcBox::<T>::try_from(v) {
93+
Ok(this) => Ok(Pin::new_unchecked(this)),
94+
Err(v) => Err(Pin::new_unchecked(v)),
95+
}
96+
}
97+
}
98+
}
99+
87100
impl<T: ?Sized> $RcBox<T> {
88101
unsafe fn from_unchecked<V>(v: V) -> Self
89102
where

0 commit comments

Comments
 (0)