Owned Pin
This crate deals with data which is owned by some entity but (maybe) immovable in memory. It is inspired by R-value references in C++.
See the documentation for more information.
Examples
With Pin<P> only, we cannot guarantee the move semantics of the value.
use ;
use PhantomPinned;
let mut value = pin!;
// The caller can reborrow the value...
try_to_take_the_ownership_of;
// ... so the same pinned data can be used twice,
// thus unable to guarantee the move semantics.
try_to_take_the_ownership_of;
But with the [OPin<T, P>] wrapper, which both "own" and "pin" the data in the memory, enabling the example above to work as desired:
use ;
use PhantomPinned;
let value = opin!;
// The `as_mut` method of `OPin` actually returns `Pin<&mut T>`...
take_the_ownership_of;
// ... so the value itself cannot be used again.
// The line below causes rustc to emit `E0382`.
// take_the_ownership_of(value);
With data that implements Unpin, we can even move it out from the wrapper safe and sound:
use ;
// Pins the value onto the stack.
let pinned = opin!;
// Retrieves back the data because `String` is `Unpin`.
let string = unpin;