Trait browser_window::prelude::rust_2024::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 an &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§

source§

impl !Unpin for PhantomPinned

source§

impl Unpin for LocalWaker

1.36.0 · source§

impl Unpin for Waker

source§

impl<'a, H, R> Unpin for DelegateFuture<'a, H, R>
where R: Send,

source§

impl<'a, R> Unpin for DelegateFutureFuture<'a, R>
where R: Send,

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>

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,

source§

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

source§

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

1.48.0 · source§

impl<T> Unpin for Ready<T>

source§

impl<T> Unpin for futures_channel::mpsc::Receiver<T>

source§

impl<T> Unpin for UnboundedReceiver<T>

source§

impl<T> Unpin for futures_channel::oneshot::Receiver<T>

source§

impl<T> Unpin for Sender<T>

source§

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

source§

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

source§

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

Auto implementors§

§

impl Unpin for Source

§

impl Unpin for JsValue

§

impl Unpin for CookieStorageError

§

impl Unpin for DelegateError

§

impl Unpin for Application

§

impl Unpin for ApplicationHandle

§

impl Unpin for ApplicationHandleThreaded

§

impl Unpin for ApplicationSettings

§

impl Unpin for Runtime

§

impl Unpin for BrowserWindow

§

impl Unpin for BrowserWindowBuilder

§

impl Unpin for BrowserWindowHandle

§

impl Unpin for BrowserWindowThreaded

§

impl Unpin for CookieJar

§

impl Unpin for Error

§

impl Unpin for BigFloat

§

impl Unpin for WindowBuilder

§

impl Unpin for WindowHandle

§

impl Unpin for WindowResizeEventArgs

§

impl Unpin for ApplicationImpl

§

impl Unpin for BrowserWindowImpl

§

impl Unpin for CookieImpl

§

impl Unpin for CookieIteratorImpl

§

impl Unpin for CookieJarImpl

§

impl Unpin for CookieMutImpl

§

impl Unpin for WindowImpl

§

impl Unpin for c_G_fpos64_t

§

impl Unpin for c_G_fpos_t

§

impl Unpin for c_IO_FILE

§

impl Unpin for c_IO_codecvt

§

impl Unpin for c_IO_marker

§

impl Unpin for c_IO_wide_data

§

impl Unpin for c__atomic_wide_counter__bindgen_ty_1

§

impl Unpin for c__fsid_t

§

impl Unpin for c__locale_data

§

impl Unpin for c__locale_struct

§

impl Unpin for c__mbstate_t

§

impl Unpin for c__once_flag

§

impl Unpin for c__pthread_cond_s

§

impl Unpin for c__pthread_internal_list

§

impl Unpin for c__pthread_internal_slist

§

impl Unpin for c__pthread_mutex_s

§

impl Unpin for c__pthread_rwlock_arch_t

§

impl Unpin for c__sigset_t

§

impl Unpin for c__va_list_tag

§

impl Unpin for cbw_Application

§

impl Unpin for cbw_ApplicationDispatchData

§

impl Unpin for cbw_ApplicationEngineData

§

impl Unpin for cbw_ApplicationEngineImpl

§

impl Unpin for cbw_ApplicationImpl

§

impl Unpin for cbw_ApplicationSettings

§

impl Unpin for cbw_BrowserWindow

§

impl Unpin for cbw_BrowserWindowImpl

§

impl Unpin for cbw_BrowserWindowOptions

§

impl Unpin for cbw_BrowserWindowSource

§

impl Unpin for cbw_CStrSlice

§

impl Unpin for cbw_CookieImpl

§

impl Unpin for cbw_CookieIterator

§

impl Unpin for cbw_CookieIteratorImpl

§

impl Unpin for cbw_CookieJar

§

impl Unpin for cbw_CookieJarImpl

§

impl Unpin for cbw_Dims2D

§

impl Unpin for cbw_Err

§

impl Unpin for cbw_Pos2D

§

impl Unpin for cbw_StrSlice

§

impl Unpin for cbw_Window

§

impl Unpin for cbw_WindowCallbacks

§

impl Unpin for cbw_WindowDispatchData

§

impl Unpin for cbw_WindowImpl

§

impl Unpin for cbw_WindowOptions

§

impl Unpin for cdiv_t

§

impl Unpin for cdrand48_data

§

impl Unpin for cfd_set

§

impl Unpin for cldiv_t

§

impl Unpin for clldiv_t

§

impl Unpin for cmax_align_t

§

impl Unpin for crandom_data

§

impl Unpin for ctimespec

§

impl Unpin for ctimeval

§

impl Unpin for c__atomic_wide_counter

§

impl Unpin for c__mbstate_t__bindgen_ty_1

§

impl Unpin for cpthread_attr_t

§

impl Unpin for cpthread_barrier_t

§

impl Unpin for cpthread_barrierattr_t

§

impl Unpin for cpthread_cond_t

§

impl Unpin for cpthread_condattr_t

§

impl Unpin for cpthread_mutex_t

§

impl Unpin for cpthread_mutexattr_t

§

impl Unpin for cpthread_rwlock_t

§

impl Unpin for cpthread_rwlockattr_t

§

impl<'a> Unpin for CookieIterator<'a>

§

impl<'a> Unpin for ContentDimensions<'a>

§

impl<'a> Unpin for Opacity<'a>

§

impl<'a> Unpin for Position<'a>

§

impl<'a> Unpin for Title<'a>

§

impl<'a> Unpin for WindowDimensions<'a>

§

impl<'a, A> Unpin for Event<'a, A>

§

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

§

impl<T, E> Unpin for Result<T, E>
where E: Unpin, T: Unpin,