Is it always safe to convert Pin<&T>
to &T
via into_inner_unchecked
? Given that the object cannot be moved from via &T
, I would assume so. I am a bit surprised the standard library does not expose a safe function to do this, so I wanted to make sure I get this right.
1 Like
Pin
implements Deref
, so you can even call functions that expect &T
or methods of T
directly on Pin<&T>
.
2 Likes
One notable difference is that … ah it says so in the docs of get_ref()
anyways
Note:
Pin
also implementsDeref
to the target, which can be used to access the inner value. However,Deref
only provides a reference that lives for as long as the borrow of thePin
, not the lifetime of thePin
itself. This method allows turning thePin
into a reference with the same lifetime as the originalPin
.
i.e. the difference is that get_ref
turns Pin<&'a T>
into &'a T
, and with the Copy
impl, this means that you can also turn &'b Pin<&'a T>
into &'a T
– whereas Deref
turns &'b Pin<&'a T>
into &'b T
.
9 Likes