#[repr(transparent)]pub struct UnsafePinned<T>where
T: ?Sized,{
value: UnsafeCell<T>,
}unsafe_pinned #125735)Expand description
This type provides a way to entirely opt-out of typical aliasing rules;
specifically, &mut UnsafePinned<T> is not guaranteed to be a unique pointer.
This also subsumes the effects of UnsafeCell, i.e., &UnsafePinned<T> may point to data
that is being mutated.
However, even if you define your type like pub struct Wrapper(UnsafePinned<...>), it is still
very risky to have an &mut Wrapper that aliases anything else. Many functions that work
generically on &mut T assume that the memory that stores T is uniquely owned (such as
mem::swap). In other words, while having aliasing with &mut Wrapper is not immediate
Undefined Behavior, it is still unsound to expose such a mutable reference to code you do not
control! Techniques such as pinning via Pin are needed to ensure soundness.
Similar to UnsafeCell, UnsafePinned will not usually show up in
the public API of a library. It is an internal implementation detail of libraries that need to
support aliasing mutable references.
This type blocks niches the same way UnsafeCell does.
Fields§
§value: UnsafeCell<T>unsafe_pinned #125735)Implementations§
Source§impl<T> UnsafePinned<T>
impl<T> UnsafePinned<T>
Sourcepub const fn new(value: T) -> UnsafePinned<T>
🔬This is a nightly-only experimental API. (unsafe_pinned #125735)
pub const fn new(value: T) -> UnsafePinned<T>
unsafe_pinned #125735)Constructs a new instance of UnsafePinned which will wrap the specified value.
All access to the inner value through &UnsafePinned<T> or &mut UnsafePinned<T> or
Pin<&mut UnsafePinned<T>> requires unsafe code.
Sourcepub const fn into_inner(self) -> T
🔬This is a nightly-only experimental API. (unsafe_pinned #125735)
pub const fn into_inner(self) -> T
unsafe_pinned #125735)Unwraps the value, consuming this UnsafePinned.
Source§impl<T> UnsafePinned<T>where
T: ?Sized,
impl<T> UnsafePinned<T>where
T: ?Sized,
Sourcepub const fn get_mut_pinned(self: Pin<&mut UnsafePinned<T>>) -> *mut T
🔬This is a nightly-only experimental API. (unsafe_pinned #125735)
pub const fn get_mut_pinned(self: Pin<&mut UnsafePinned<T>>) -> *mut T
unsafe_pinned #125735)Get read-write access to the contents of a pinned UnsafePinned.
Sourcepub const fn get_mut_unchecked(&mut self) -> *mut T
🔬This is a nightly-only experimental API. (unsafe_pinned #125735)
pub const fn get_mut_unchecked(&mut self) -> *mut T
unsafe_pinned #125735)Get read-write access to the contents of an UnsafePinned.
You should usually be using get_mut_pinned instead to explicitly track the fact that this
memory is “pinned” due to there being aliases.
Sourcepub const fn get(&self) -> *mut T
🔬This is a nightly-only experimental API. (unsafe_pinned #125735)
pub const fn get(&self) -> *mut T
unsafe_pinned #125735)Get mutable access to the contents of a shared UnsafePinned.
This can be cast to a pointer of any kind. When creating references, you must uphold the
aliasing rules; see UnsafeCell for more discussion and caveats.
Sourcepub const fn raw_get(this: *const UnsafePinned<T>) -> *mut T
🔬This is a nightly-only experimental API. (unsafe_pinned #125735)
pub const fn raw_get(this: *const UnsafePinned<T>) -> *mut T
unsafe_pinned #125735)Gets an immutable pointer to the wrapped value.
The difference from get is that this function accepts a raw pointer, which is useful to
avoid the creation of temporary references.
Sourcepub const fn raw_get_mut(this: *mut UnsafePinned<T>) -> *mut T
🔬This is a nightly-only experimental API. (unsafe_pinned #125735)
pub const fn raw_get_mut(this: *mut UnsafePinned<T>) -> *mut T
unsafe_pinned #125735)Gets a mutable pointer to the wrapped value.
The difference from get_mut_pinned and get_mut_unchecked is that this function
accepts a raw pointer, which is useful to avoid the creation of temporary references.
Trait Implementations§
Source§impl<T> Debug for UnsafePinned<T>where
T: ?Sized,
impl<T> Debug for UnsafePinned<T>where
T: ?Sized,
Source§impl<T> Default for UnsafePinned<T>where
T: Default,
impl<T> Default for UnsafePinned<T>where
T: Default,
Source§fn default() -> UnsafePinned<T>
fn default() -> UnsafePinned<T>
Creates an UnsafePinned, with the Default value for T.
Source§impl<T> From<T> for UnsafePinned<T>
impl<T> From<T> for UnsafePinned<T>
Source§fn from(value: T) -> UnsafePinned<T>
fn from(value: T) -> UnsafePinned<T>
Creates a new UnsafePinned<T> containing the given value.
impl<T, U> CoerceUnsized<UnsafePinned<U>> for UnsafePinned<T>where
T: CoerceUnsized<U>,
impl<T, U> DispatchFromDyn<UnsafePinned<U>> for UnsafePinned<T>where
T: DispatchFromDyn<U>,
impl<T> Sync for UnsafePinned<T>
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.
Auto Trait Implementations§
impl<T> !Freeze for UnsafePinned<T>
impl<T> !RefUnwindSafe for UnsafePinned<T>
impl<T> Send for UnsafePinned<T>
impl<T> UnwindSafe for UnsafePinned<T>where
T: UnwindSafe + ?Sized,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> SizedTypeProperties for T
impl<T> SizedTypeProperties for T
Source§#[doc(hidden)] const SIZE: usize = _
#[doc(hidden)] const SIZE: usize = _
sized_type_properties)Source§#[doc(hidden)] const ALIGN: usize = _
#[doc(hidden)] const ALIGN: usize = _
sized_type_properties)Source§#[doc(hidden)] const IS_ZST: bool = _
#[doc(hidden)] const IS_ZST: bool = _
sized_type_properties)Source§#[doc(hidden)] const LAYOUT: Layout = _
#[doc(hidden)] const LAYOUT: Layout = _
sized_type_properties)Source§#[doc(hidden)] const MAX_SLICE_LEN: usize = _
#[doc(hidden)] const MAX_SLICE_LEN: usize = _
sized_type_properties)[Self]. Read more