Trait standback::marker::Unpin 1.33.0[−][src]
Types that can be safely moved after being pinned.
Rust itself has no notion of immovable types, and considers moves (e.g.,
through assignment or mem::replace
) to always be safe.
The Pin
type is used instead to prevent moves through the type
system. Pointers P<T>
wrapped in the Pin<P<T>>
wrapper can’t be
moved out of. See the pin
module documentation for more information on
pinning.
Implementing the Unpin
trait for T
lifts the restrictions of pinning off
the type, which then allows moving T
out of Pin<P<T>>
with
functions such as mem::replace
.
Unpin
has no consequence at all for non-pinned data. In particular,
mem::replace
happily moves !Unpin
data (it works for any &mut T
, not
just when T: Unpin
). However, you cannot use mem::replace
on data
wrapped inside a Pin<P<T>>
because you cannot get the &mut T
you
need for that, and that is what makes this system work.
So this, for example, can only be done on types implementing Unpin
:
use std::mem; use std::pin::Pin; let mut string = "this".to_string(); let mut pinned_string = Pin::new(&mut string); // We need a mutable reference to call `mem::replace`. // We can obtain such a reference by (implicitly) invoking `Pin::deref_mut`, // but that is only possible because `String` implements `Unpin`. mem::replace(&mut *pinned_string, "other".to_string());
This trait is automatically implemented for almost every type.
Implementations on Foreign Types
impl<T> Unpin for Ready<T>
[src]
impl<T> Unpin for *const T where
T: ?Sized,
[src]
T: ?Sized,
impl<F> Unpin for PollFn<F>
[src]
impl !Unpin for PhantomPinned
[src]
impl<T> Unpin for Pending<T>
[src]
impl<'a, T> Unpin for &'a mut T where
T: 'a + ?Sized,
[src]
T: 'a + ?Sized,
impl<T> Unpin for *mut T where
T: ?Sized,
[src]
T: ?Sized,
impl<'a, T> Unpin for &'a T where
T: 'a + ?Sized,
[src]
T: 'a + ?Sized,
impl<Dyn> Unpin for DynMetadata<Dyn> where
Dyn: ?Sized,
[src]
Dyn: ?Sized,
impl<T> Unpin for Arc<T> where
T: ?Sized,
[src]
T: ?Sized,
impl<T, A> Unpin for Box<T, A> where
T: ?Sized,
A: Allocator + 'static,
[src]
T: ?Sized,
A: Allocator + 'static,
impl<T> Unpin for Rc<T> where
T: ?Sized,
[src]
T: ?Sized,
impl Unpin for isize
impl<T> Unpin for [T] where
T: Unpin,
T: Unpin,
impl Unpin for [u8]
impl Unpin for char
impl Unpin for u128
impl Unpin for u16
impl Unpin for i128
impl Unpin for i16
impl Unpin for str
impl Unpin for f64
impl Unpin for u64
impl Unpin for u8
impl Unpin for i64
impl Unpin for i8
impl<T, const N: usize> Unpin for [T; N] where
T: Unpin,
T: Unpin,
impl Unpin for bool
impl Unpin for f32
impl Unpin for u32
impl Unpin for usize
impl Unpin for i32
Loading content...Implementors
Loading content...Auto implementors
impl Unpin for Infallible
impl Unpin for TryFromSliceError
impl Unpin for TryFromIntError
impl Unpin for RawWaker
impl Unpin for RawWakerVTable
impl<'a> Unpin for Context<'a>
impl<F> Unpin for OnceWith<F> where
F: Unpin,
F: Unpin,
impl<I> Unpin for Copied<I> where
I: Unpin,
I: Unpin,
impl<P> Unpin for Pin<P> where
P: Unpin,
P: Unpin,
impl<T> Unpin for Poll<T> where
T: Unpin,
T: Unpin,
impl<T> Unpin for MaybeUninit<T> where
T: Unpin,
T: Unpin,