Trait core::marker::Unpin

1.33.0 · source · []
pub auto trait Unpin { }
Expand description

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());
Run

This trait is automatically implemented for almost every type.

Implementors

impl<T: ?Sized, A: Allocator> Unpin for Box<T, A>where
    A: 'static,

Auto implementors

impl Unpin for Global

impl<T: ?Sized> Unpin for ThinBox<T>where
    T: Unpin,

impl<'a, B: ?Sized> Unpin for Cow<'a, B>where
    <B as ToOwned>::Owned: Unpin,

impl Unpin for String

impl<'a> Unpin for Drain<'a>

impl<'a, T, F, A> Unpin for DrainFilter<'a, T, F, A>where
    F: Unpin,

impl<'a, T, A> Unpin for Drain<'a, T, A>

impl<T, A> Unpin for IntoIter<T, A>where
    A: Unpin,
    T: Unpin,

impl<T, A> Unpin for Vec<T, A>where
    A: Unpin,
    T: Unpin,

impl Unpin for Error

impl Unpin for CStr

impl Unpin for CString

impl<T: ?Sized> Unpin for Arc<T>where
    T: Unpin,

impl<'a, T: ?Sized> Unpin for ArcBorrow<'a, T>

impl<T: ?Sized> Unpin for UniqueArc<T>where
    T: Unpin,

impl<T: ?Sized> Unpin for StaticArc<T>where
    T: Unpin,

impl !Unpin for CondVar

impl<'a, L: ?Sized, I> Unpin for Guard<'a, L, I>where
    <L as Lock<I>>::GuardContext: Unpin,

impl Unpin for ReadLock

impl Unpin for WriteLock

impl<T: ?Sized, L: ?Sized> Unpin for LockedBy<T, L>where
    T: Unpin,

impl<T> !Unpin for Mutex<T>

impl<T: ?Sized> Unpin for NoWaitLock<T>where
    T: Unpin,

impl<'a, T: ?Sized> Unpin for NoWaitLockGuard<'a, T>

impl Unpin for Guard

impl<F, T> Unpin for Revocable<F, T>where
    <F as LockFactory>::LockedType<Inner<T>>: Unpin,

impl<'a, F, T, I> Unpin for RevocableGuard<'a, F, T, I>where
    <<F as LockFactory>::LockedType<Inner<T>> as Lock<I>>::GuardContext: Unpin,

impl<T> !Unpin for RwSemaphore<T>

impl<L> !Unpin for SeqLock<L>

impl<'a, L: ?Sized> Unpin for SeqLockReadGuard<'a, L>

impl<T: ?Sized> Unpin for Mutex<T>where
    T: Unpin,

impl<T> !Unpin for SpinLock<T>

impl<T> !Unpin for RawSpinLock<T>

impl Unpin for Mode

impl<T, F> Unpin for ScopeGuard<T, F>where
    F: Unpin,
    T: Unpin,

impl<T> Unpin for Opaque<T>where
    T: Unpin,

impl<T> Unpin for Bit<T>where
    T: Unpin,

impl Unpin for True

impl Unpin for False

impl<T> Unpin for ARef<T>where
    T: Unpin,

impl<L, R> Unpin for Either<L, R>where
    L: Unpin,
    R: Unpin,

impl<const N: usize> !Unpin for Registration<N>

impl Unpin for Clk

impl Unpin for EnabledClk

impl Unpin for Credential

impl Unpin for Device

impl<T, U, V> !Unpin for Data<T, U, V>

impl<T> Unpin for Registration<T>where
    <T as DriverOps>::RegType: Unpin,

impl<T, U, const N: usize> Unpin for IdArray<T, U, N>where
    U: Unpin,
    <T as RawDeviceId>::RawType: Unpin,

impl<'a, T, U> Unpin for IdTable<'a, T, U>

impl<T> Unpin for Module<T>

impl Unpin for File

impl Unpin for PollTable

impl Unpin for SeekFrom

impl<'a> Unpin for Value<'a>

impl Unpin for Spec

impl<const N: usize, S> Unpin for SpecArray<N, S>

impl<'a, S> Unpin for SpecTable<'a, S>where
    S: Unpin,

impl<const N: usize> Unpin for ConstantArray<N>

impl<'a> Unpin for ConstantTable<'a>

impl Unpin for Super

impl Unpin for NeedsInit

impl Unpin for NeedsRoot

impl<'a, T: ?Sized, S> Unpin for NewSuperBlock<'a, T, S>where
    S: Unpin,

impl<T: ?Sized> Unpin for SuperBlock<T>where
    T: Unpin,

impl Unpin for INode

impl Unpin for DEntry

impl Unpin for Filename

impl<T> Unpin for Module<T>where
    T: Unpin,

impl<T> !Unpin for Registration<T>

impl<T> Unpin for Registration<T>where
    T: Unpin,

impl Unpin for IrqData

impl Unpin for Type

impl Unpin for Descriptor

impl<H> Unpin for Registration<H>where
    <H as Handler>::Data: Unpin,

impl<H> Unpin for ThreadedRegistration<H>where
    <H as ThreadedHandler>::Data: Unpin,

impl Unpin for Return

impl<'a> Unpin for ChainedGuard<'a>

impl Unpin for Domain

impl !Unpin for Executor

impl<T: ?Sized> Unpin for AutoStopHandle<T>where
    T: Unpin,

impl Unpin for TcpStream

impl<'a> Unpin for Options<'a>

impl<T> !Unpin for Registration<T>

impl<T> Unpin for Module<T>

impl Unpin for Area

impl Unpin for Hook

impl Unpin for Hook

impl Unpin for Hook

impl Unpin for Family

impl<T> !Unpin for Registration<T>

impl Unpin for Device

impl Unpin for Namespace

impl Unpin for SkBuff

impl Unpin for Ipv4Addr

impl Unpin for Ipv6Addr

impl Unpin for SocketAddr

impl Unpin for TcpStream

impl<const ORDER: u32> Unpin for Pages<ORDER>

impl<T> Unpin for NoOperations<T>where
    T: Unpin,

impl<T> Unpin for Revocable<T>where
    T: Unpin,

impl<'a, T> Unpin for RevocableGuard<'a, T>

impl<T> Unpin for AsyncRevocable<T>where
    T: Unpin,

impl<'a, T> Unpin for AsyncRevocableGuard<'a, T>

impl Unpin for Task

impl<'a> Unpin for TaskRef<'a>

impl Unpin for Queue

impl Unpin for Work

impl Unpin for BoxedQueue

impl<'a, G> Unpin for Cursor<'a, G>

impl<T: ?Sized> Unpin for Links<T>

impl<G> Unpin for List<G>

impl<'a, G> Unpin for CursorMut<'a, G>

impl<K, V> Unpin for RBTree<K, V>where
    K: Unpin,
    V: Unpin,

impl<'a, K, V> Unpin for RBTreeIterator<'a, K, V>

impl<'a, K, V> Unpin for RBTreeIteratorMut<'a, K, V>

impl<K, V> Unpin for RBTreeNodeReservation<K, V>

impl<K, V> Unpin for RBTreeNode<K, V>

impl<A: ?Sized> Unpin for List<A>

impl<'a, A: ?Sized> Unpin for Iterator<'a, A>

impl<T> !Unpin for Links<T>

impl<'a, A: ?Sized> Unpin for Cursor<'a, A>

impl<T> Unpin for Sysctl<T>

impl Unpin for Resource

impl<const SIZE: usize> Unpin for IoMem<SIZE>

impl Unpin for IovIter

impl Unpin for DeviceId

impl<T> Unpin for Adapter<T>where
    T: Unpin,

impl Unpin for Device

impl Unpin for ThisModule

impl<'a> Unpin for KParamGuard<'a>

This documentation is an old archive. Please see https://rust.docs.kernel.org instead.