Unpin

Trait Unpin 

1.33.0 · Source
pub auto trait Unpin { }
Expand description

Types that do not require any pinning guarantees.

For information on what “pinning” is, see the pin module documentation.

Implementing the Unpin trait for T expresses the fact that T is pinning-agnostic: it shall not expose nor rely on any pinning guarantees. This, in turn, means that a Pin-wrapped pointer to such a type can feature a fully unrestricted API. In other words, if T: Unpin, a value of type T will not be bound by the invariants which pinning otherwise offers, even when “pinned” by a Pin<Ptr> pointing at it. When a value of type T is pointed at by a Pin<Ptr>, Pin will not restrict access to the pointee value like it normally would, thus allowing the user to do anything that they normally could with a non-Pin-wrapped Ptr to that value.

The idea of this trait is to alleviate the reduced ergonomics of APIs that require the use of Pin for soundness for some types, but which also want to be used by other types that don’t care about pinning. The prime example of such an API is Future::poll. There are many Future types that don’t care about pinning. These futures can implement Unpin and therefore get around the pinning related restrictions in the API, while still allowing the subset of Futures which do require pinning to be implemented soundly.

For more discussion on the consequences of Unpin within the wider scope of the pinning system, see the section about Unpin in the pin module.

Unpin has no consequence at all for non-pinned data. In particular, mem::replace happily moves !Unpin data, which would be immovable when pinned (mem::replace works for any &mut T, not just when T: Unpin).

However, you cannot use mem::replace on !Unpin data which is pinned by being wrapped inside a Pin<Ptr> pointing at it. This is because you cannot (safely) use a Pin<Ptr> to get a &mut T to its pointee value, which you would need to call mem::replace, 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. The compiler is free to take the conservative stance of marking types as Unpin so long as all of the types that compose its fields are also Unpin. This is because if a type implements Unpin, then it is unsound for that type’s implementation to rely on pinning-related guarantees for soundness, even when viewed through a “pinning” pointer! It is the responsibility of the implementor of a type that relies upon pinning for soundness to ensure that type is not marked as Unpin by adding PhantomPinned field. For more details, see the pin module docs.

Implementors§

1.33.0 · Source§

impl !Unpin for PhantomPinned

Source§

impl Unpin for LocalWaker

1.36.0 · Source§

impl Unpin for Waker

Source§

impl<Dyn> Unpin for DynMetadata<Dyn>
where Dyn: ?Sized,

1.64.0 · Source§

impl<F> Unpin for PollFn<F>
where F: Unpin,

Source§

impl<I> Unpin for FromIter<I>

Source§

impl<T> !Unpin for UnsafePinned<T>
where T: ?Sized,

When this type is used, that almost certainly means safe APIs need to use pinning to avoid the aliases from becoming invalidated. Therefore let’s mark this as !Unpin. You can always opt back in to Unpin with an impl block, provided your API is still sound while unpinned.

1.38.0 · Source§

impl<T> Unpin for *const T
where T: ?Sized,

1.38.0 · Source§

impl<T> Unpin for *mut T
where T: ?Sized,

1.33.0 · Source§

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

1.33.0 · Source§

impl<T> Unpin for &mut T
where T: ?Sized,

1.28.0 · Source§

impl<T> Unpin for NonZero<T>

1.48.0 · Source§

impl<T> Unpin for Ready<T>

1.33.0 · Source§

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

1.33.0 · Source§

impl<T, A> Unpin for Rc<T, A>
where A: Allocator, T: ?Sized,

Source§

impl<T, A> Unpin for UniqueRc<T, A>
where A: Allocator, T: ?Sized,

1.33.0 · Source§

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

Source§

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

Auto implementors§

§

impl Unpin for NamedFields

§

impl Unpin for NoFields

§

impl Unpin for UnnamedFields

§

impl Unpin for NameAssigned

§

impl Unpin for NameNotAssigned

§

impl Unpin for TypeAssigned

§

impl Unpin for TypeNotAssigned

§

impl Unpin for PathAssigned

§

impl Unpin for PathNotAssigned

§

impl Unpin for IndexAssigned

§

impl Unpin for IndexNotAssigned

§

impl Unpin for PathError

§

impl Unpin for TypeDefPrimitive

§

impl Unpin for MetaForm

§

impl Unpin for PortableForm

§

impl Unpin for Ordering

§

impl Unpin for TryReserveErrorKind

§

impl Unpin for Alignment

§

impl Unpin for DebugAsHex

§

impl Unpin for scale_info::prelude::fmt::Sign

§

impl Unpin for FpCategory

§

impl Unpin for IntErrorKind

§

impl Unpin for OneSidedRangeBound

§

impl Unpin for MetaType

§

impl Unpin for PortableRegistry

§

impl Unpin for PortableRegistryBuilder

§

impl Unpin for PortableType

§

impl Unpin for Registry

§

impl Unpin for TypeId

§

impl Unpin for UnorderedKeyError

§

impl Unpin for TryReserveError

§

impl Unpin for Error

§

impl Unpin for FormattingOptions

§

impl Unpin for SipHasher

§

impl Unpin for Assume

§

impl Unpin for ParseFloatError

§

impl Unpin for ParseIntError

§

impl Unpin for TryFromIntError

§

impl Unpin for RangeFull

§

impl Unpin for FromUtf8Error

§

impl Unpin for FromUtf16Error

§

impl Unpin for IntoChars

§

impl Unpin for String

§

impl Unpin for Duration

§

impl Unpin for TryFromFloatSecsError

§

impl Unpin for Big8x3

§

impl Unpin for Big32x40

§

impl Unpin for CodePointInner

§

impl Unpin for Decimal

§

impl Unpin for DecimalSeq

§

impl Unpin for Decoded

§

impl Unpin for FullDecoded

§

impl Unpin for I32NotAllOnes

§

impl Unpin for I64NotAllOnes

§

impl Unpin for Nanoseconds

§

impl Unpin for NonZeroCharInner

§

impl Unpin for NonZeroI8Inner

§

impl Unpin for NonZeroI16Inner

§

impl Unpin for NonZeroI32Inner

§

impl Unpin for NonZeroI64Inner

§

impl Unpin for NonZeroI128Inner

§

impl Unpin for NonZeroIsizeInner

§

impl Unpin for NonZeroU8Inner

§

impl Unpin for NonZeroU16Inner

§

impl Unpin for NonZeroU32Inner

§

impl Unpin for NonZeroU64Inner

§

impl Unpin for NonZeroU128Inner

§

impl Unpin for NonZeroUsizeInner

§

impl Unpin for Sign

§

impl Unpin for U32NotAllOnes

§

impl Unpin for U64NotAllOnes

§

impl Unpin for UsizeNoHighBit

§

impl<'a> Unpin for Arguments<'a>

§

impl<'a> Unpin for Formatter<'a>

§

impl<'a> Unpin for scale_info::prelude::string::Drain<'a>

§

impl<'a> Unpin for PhantomContravariantLifetime<'a>

§

impl<'a> Unpin for PhantomCovariantLifetime<'a>

§

impl<'a> Unpin for PhantomInvariantLifetime<'a>

§

impl<'a> Unpin for Formatted<'a>

§

impl<'a> Unpin for Part<'a>

§

impl<'a, 'b> Unpin for DebugList<'a, 'b>

§

impl<'a, 'b> Unpin for DebugMap<'a, 'b>

§

impl<'a, 'b> Unpin for DebugSet<'a, 'b>

§

impl<'a, 'b> Unpin for DebugStruct<'a, 'b>

§

impl<'a, 'b> Unpin for DebugTuple<'a, 'b>

§

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

§

impl<'a, I> Unpin for ByRefSized<'a, I>

§

impl<'a, I, A> Unpin for Splice<'a, I, A>
where I: Unpin,

§

impl<'a, K> Unpin for scale_info::prelude::collections::btree_set::Cursor<'a, K>

§

impl<'a, K, A> Unpin for scale_info::prelude::collections::btree_set::CursorMut<'a, K, A>

§

impl<'a, K, A> Unpin for scale_info::prelude::collections::btree_set::CursorMutKey<'a, K, A>

§

impl<'a, K, V> Unpin for scale_info::prelude::collections::btree_map::Cursor<'a, K, V>

§

impl<'a, K, V> Unpin for scale_info::prelude::collections::btree_map::Iter<'a, K, V>

§

impl<'a, K, V> Unpin for scale_info::prelude::collections::btree_map::IterMut<'a, K, V>

§

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

§

impl<'a, K, V> Unpin for scale_info::prelude::collections::btree_map::Range<'a, K, V>

§

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

§

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

§

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

§

impl<'a, K, V, A> Unpin for scale_info::prelude::collections::btree_map::Entry<'a, K, V, A>
where K: Unpin, A: Unpin,

§

impl<'a, K, V, A> Unpin for scale_info::prelude::collections::btree_map::CursorMut<'a, K, V, A>

§

impl<'a, K, V, A> Unpin for scale_info::prelude::collections::btree_map::CursorMutKey<'a, K, V, A>

§

impl<'a, K, V, A> Unpin for scale_info::prelude::collections::btree_map::OccupiedEntry<'a, K, V, A>
where A: Unpin,

§

impl<'a, K, V, A> Unpin for OccupiedError<'a, K, V, A>
where V: Unpin, A: Unpin,

§

impl<'a, K, V, A> Unpin for scale_info::prelude::collections::btree_map::VacantEntry<'a, K, V, A>
where K: Unpin, A: Unpin,

§

impl<'a, K, V, R, F, A> Unpin for scale_info::prelude::collections::btree_map::ExtractIf<'a, K, V, R, F, A>
where F: Unpin, A: Unpin, R: Unpin,

§

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

§

impl<'a, T> Unpin for scale_info::prelude::collections::binary_heap::Iter<'a, T>

§

impl<'a, T> Unpin for scale_info::prelude::collections::btree_set::Iter<'a, T>

§

impl<'a, T> Unpin for scale_info::prelude::collections::btree_set::Range<'a, T>

§

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

§

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

§

impl<'a, T> Unpin for scale_info::prelude::collections::linked_list::Iter<'a, T>

§

impl<'a, T> Unpin for scale_info::prelude::collections::linked_list::IterMut<'a, T>

§

impl<'a, T> Unpin for scale_info::prelude::collections::vec_deque::Iter<'a, T>

§

impl<'a, T> Unpin for scale_info::prelude::collections::vec_deque::IterMut<'a, T>

§

impl<'a, T> Unpin for scale_info::prelude::vec::PeekMut<'a, T>

§

impl<'a, T, A> Unpin for scale_info::prelude::collections::btree_set::Entry<'a, T, A>
where A: Unpin, T: Unpin,

§

impl<'a, T, A> Unpin for scale_info::prelude::collections::binary_heap::Drain<'a, T, A>

§

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

§

impl<'a, T, A> Unpin for scale_info::prelude::collections::binary_heap::PeekMut<'a, T, A>

§

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

§

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

§

impl<'a, T, A> Unpin for scale_info::prelude::collections::btree_set::OccupiedEntry<'a, T, A>
where A: Unpin,

§

impl<'a, T, A> Unpin for scale_info::prelude::collections::btree_set::VacantEntry<'a, T, A>
where T: Unpin, A: Unpin,

§

impl<'a, T, A> Unpin for scale_info::prelude::collections::linked_list::Cursor<'a, T, A>

§

impl<'a, T, A> Unpin for scale_info::prelude::collections::linked_list::CursorMut<'a, T, A>

§

impl<'a, T, A> Unpin for scale_info::prelude::collections::vec_deque::Drain<'a, T, A>

§

impl<'a, T, A> Unpin for scale_info::prelude::vec::Drain<'a, T, A>

§

impl<'a, T, F, A> Unpin for scale_info::prelude::collections::linked_list::ExtractIf<'a, T, F, A>
where F: Unpin,

§

impl<'a, T, F, A> Unpin for scale_info::prelude::vec::ExtractIf<'a, T, F, A>
where F: Unpin,

§

impl<'a, T, R, F, A> Unpin for scale_info::prelude::collections::btree_set::ExtractIf<'a, T, R, F, A>
where F: Unpin, A: Unpin, R: Unpin,

§

impl<A> Unpin for Repeat<A>
where A: Unpin,

§

impl<A> Unpin for RepeatN<A>
where A: Unpin,

§

impl<A, B> Unpin for Chain<A, B>
where A: Unpin, B: Unpin,

§

impl<A, B> Unpin for Zip<A, B>
where A: Unpin, B: Unpin,

§

impl<B, C> Unpin for ControlFlow<B, C>
where C: Unpin, B: Unpin,

§

impl<F> Unpin for Fields<F>

§

impl<F> Unpin for Variants<F>
where <F as Form>::String: Unpin, <F as Form>::Type: Unpin,

§

impl<F> Unpin for scale_info::prelude::fmt::FromFn<F>
where F: Unpin,

§

impl<F> Unpin for scale_info::prelude::iter::FromFn<F>
where F: Unpin,

§

impl<F> Unpin for OnceWith<F>
where F: Unpin,

§

impl<F> Unpin for RepeatWith<F>
where F: Unpin,

§

impl<F, N, T> Unpin for FieldBuilder<F, N, T>
where <F as Form>::String: Unpin, <F as Form>::Type: Unpin,

§

impl<F, S> Unpin for TypeBuilder<F, S>
where <F as Form>::String: Unpin, <F as Form>::Type: Unpin,

§

impl<F, S> Unpin for VariantBuilder<F, S>
where <F as Form>::String: Unpin, S: Unpin, <F as Form>::Type: Unpin,

§

impl<F, T> Unpin for FieldsBuilder<F, T>
where <F as Form>::Type: Unpin, <F as Form>::String: Unpin,

§

impl<G> Unpin for FromCoroutine<G>
where G: Unpin,

§

impl<H> Unpin for BuildHasherDefault<H>

§

impl<I> Unpin for Cloned<I>
where I: Unpin,

§

impl<I> Unpin for Copied<I>
where I: Unpin,

§

impl<I> Unpin for Cycle<I>
where I: Unpin,

§

impl<I> Unpin for Enumerate<I>
where I: Unpin,

§

impl<I> Unpin for Flatten<I>
where <<I as Iterator>::Item as IntoIterator>::IntoIter: Unpin, I: Unpin,

§

impl<I> Unpin for Fuse<I>
where I: Unpin,

§

impl<I> Unpin for Intersperse<I>
where <I as Iterator>::Item: Sized + Unpin, I: Unpin,

§

impl<I> Unpin for Peekable<I>
where I: Unpin, <I as Iterator>::Item: Unpin,

§

impl<I> Unpin for Skip<I>
where I: Unpin,

§

impl<I> Unpin for StepBy<I>
where I: Unpin,

§

impl<I> Unpin for Take<I>
where I: Unpin,

§

impl<I, F> Unpin for FilterMap<I, F>
where I: Unpin, F: Unpin,

§

impl<I, F> Unpin for Inspect<I, F>
where I: Unpin, F: Unpin,

§

impl<I, F> Unpin for Map<I, F>
where I: Unpin, F: Unpin,

§

impl<I, F, const N: usize> Unpin for MapWindows<I, F, N>
where F: Unpin, I: Unpin, <I as Iterator>::Item: Unpin,

§

impl<I, G> Unpin for IntersperseWith<I, G>
where G: Unpin, <I as Iterator>::Item: Unpin, I: Unpin,

§

impl<I, P> Unpin for Filter<I, P>
where I: Unpin, P: Unpin,

§

impl<I, P> Unpin for MapWhile<I, P>
where I: Unpin, P: Unpin,

§

impl<I, P> Unpin for SkipWhile<I, P>
where I: Unpin, P: Unpin,

§

impl<I, P> Unpin for TakeWhile<I, P>
where I: Unpin, P: Unpin,

§

impl<I, St, F> Unpin for Scan<I, St, F>
where I: Unpin, F: Unpin, St: Unpin,

§

impl<I, U, F> Unpin for FlatMap<I, U, F>
where <U as IntoIterator>::IntoIter: Unpin, I: Unpin, F: Unpin,

§

impl<I, const N: usize> Unpin for ArrayChunks<I, N>
where I: Unpin, <I as Iterator>::Item: Unpin,

§

impl<Idx> Unpin for scale_info::prelude::ops::Range<Idx>
where Idx: Unpin,

§

impl<Idx> Unpin for RangeFrom<Idx>
where Idx: Unpin,

§

impl<Idx> Unpin for RangeInclusive<Idx>
where Idx: Unpin,

§

impl<Idx> Unpin for RangeTo<Idx>
where Idx: Unpin,

§

impl<Idx> Unpin for RangeToInclusive<Idx>
where Idx: Unpin,

§

impl<K, V, A> Unpin for scale_info::prelude::collections::btree_map::IntoIter<K, V, A>
where A: Unpin,

§

impl<K, V, A> Unpin for IntoKeys<K, V, A>
where A: Unpin,

§

impl<K, V, A> Unpin for IntoValues<K, V, A>
where A: Unpin,

§

impl<K, V, A> Unpin for BTreeMap<K, V, A>
where A: Unpin,

§

impl<T> Unpin for TypeDef<T>
where <T as Form>::Type: Unpin, <T as Form>::String: Unpin,

§

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

§

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

§

impl<T> Unpin for UntrackedSymbol<T>

§

impl<T> Unpin for Field<T>
where <T as Form>::Type: Unpin, <T as Form>::String: Unpin,

§

impl<T> Unpin for Path<T>
where <T as Form>::String: Unpin,

§

impl<T> Unpin for Type<T>
where <T as Form>::Type: Unpin, <T as Form>::String: Unpin,

§

impl<T> Unpin for TypeDefArray<T>
where <T as Form>::Type: Unpin,

§

impl<T> Unpin for TypeDefBitSequence<T>
where <T as Form>::Type: Unpin,

§

impl<T> Unpin for TypeDefCompact<T>
where <T as Form>::Type: Unpin,

§

impl<T> Unpin for TypeDefComposite<T>
where <T as Form>::Type: Unpin, <T as Form>::String: Unpin,

§

impl<T> Unpin for TypeDefSequence<T>
where <T as Form>::Type: Unpin,

§

impl<T> Unpin for TypeDefTuple<T>
where <T as Form>::Type: Unpin,

§

impl<T> Unpin for TypeDefVariant<T>
where <T as Form>::String: Unpin, <T as Form>::Type: Unpin,

§

impl<T> Unpin for TypeParameter<T>
where <T as Form>::String: Unpin, <T as Form>::Type: Unpin,

§

impl<T> Unpin for Variant<T>
where <T as Form>::String: Unpin, <T as Form>::Type: Unpin,

§

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

§

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

§

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

§

impl<T> Unpin for Empty<T>

§

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

§

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

§

impl<T> Unpin for Discriminant<T>

§

impl<T> Unpin for ManuallyDrop<T>
where T: Unpin + ?Sized,

§

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

§

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

§

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

§

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

§

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

§

impl<T> Unpin for PhantomData<T>
where T: Unpin + ?Sized,

§

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

§

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

§

impl<T, A> Unpin for scale_info::prelude::collections::binary_heap::IntoIter<T, A>
where T: Unpin, A: Unpin,

§

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

§

impl<T, A> Unpin for scale_info::prelude::collections::btree_set::IntoIter<T, A>
where A: Unpin,

§

impl<T, A> Unpin for scale_info::prelude::collections::linked_list::IntoIter<T, A>
where A: Unpin,

§

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

§

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

§

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

§

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

§

impl<T, A> Unpin for scale_info::prelude::collections::vec_deque::IntoIter<T, A>
where A: Unpin, T: Unpin,

§

impl<T, A> Unpin for scale_info::prelude::rc::Weak<T, A>
where A: Unpin, T: ?Sized,

§

impl<T, A> Unpin for scale_info::prelude::sync::Weak<T, A>
where A: Unpin, T: ?Sized,

§

impl<T, A> Unpin for scale_info::prelude::vec::IntoIter<T, A>
where T: Unpin, A: Unpin,

§

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

§

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

§

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

§

impl<Y, R> Unpin for CoroutineState<Y, R>
where Y: Unpin, R: Unpin,