#[repr(transparent)]pub struct UnsafePinned<T>where
T: ?Sized,{
value: UnsafeCell<T>,
}
unsafe_pinned
)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
)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
)
pub const fn new(value: T) -> UnsafePinned<T>
unsafe_pinned
)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
)
pub const fn into_inner(self) -> T
unsafe_pinned
)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
)
pub const fn get_mut_pinned(self: Pin<&mut UnsafePinned<T>>) -> *mut T
unsafe_pinned
)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
)
pub const fn get_mut_unchecked(&mut self) -> *mut T
unsafe_pinned
)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
)
pub const fn get(&self) -> *mut T
unsafe_pinned
)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.
#![feature(unsafe_pinned)]
use std::pin::UnsafePinned;
unsafe {
let mut x = UnsafePinned::new(0);
let ptr = x.get();
x.get_mut_unchecked().write(1);
assert_eq!(ptr.read(), 1);
}
Sourcepub const fn raw_get(this: *const UnsafePinned<T>) -> *const T
๐ฌThis is a nightly-only experimental API. (unsafe_pinned
)
pub const fn raw_get(this: *const UnsafePinned<T>) -> *const T
unsafe_pinned
)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
)
pub const fn raw_get_mut(this: *mut UnsafePinned<T>) -> *mut T
unsafe_pinned
)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<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
Sourceยงfn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
Sourceยงfn adapt_into(self) -> D
fn adapt_into(self) -> D
ยงimpl<T> ArchivePointee for T
impl<T> ArchivePointee for T
ยงtype ArchivedMetadata = ()
type ArchivedMetadata = ()
ยงfn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Sourceยงimpl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
Sourceยงfn arrays_from(colors: C) -> T
fn arrays_from(colors: C) -> T
Sourceยงimpl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
Sourceยงfn arrays_into(self) -> C
fn arrays_into(self) -> C
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<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
impl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
Sourceยงtype Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
parameters
when converting.Sourceยงfn cam16_into_unclamped(
self,
parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>,
) -> T
fn cam16_into_unclamped( self, parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>, ) -> T
self
into C
, using the provided parameters.Sourceยงimpl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
Sourceยงfn components_from(colors: C) -> T
fn components_from(colors: C) -> T
ยงimpl<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<F, W, T, D> Deserialize<With<T, W>, D> for F
ยงfn deserialize(
&self,
deserializer: &mut D,
) -> Result<With<T, W>, <D as Fallible>::Error>
fn deserialize( &self, deserializer: &mut D, ) -> Result<With<T, W>, <D as Fallible>::Error>
ยงimpl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
ยงfn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
, which can then be
downcast
into Box<dyn ConcreteType>
where ConcreteType
implements Trait
.ยงfn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
, which can then be further
downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.ยงfn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
โs vtable from &Trait
โs.ยงfn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
โs vtable from &mut Trait
โs.ยงimpl<T> DowncastSend for T
impl<T> DowncastSend for T
ยงimpl<T> DowncastSync for T
impl<T> DowncastSync for T
Sourceยงimpl<T> FromAngle<T> for T
impl<T> FromAngle<T> for T
Sourceยงfn from_angle(angle: T) -> T
fn from_angle(angle: T) -> T
angle
.ยงimpl<E, T, Request> FromReq<StreamingText, Request, E> for T
impl<E, T, Request> FromReq<StreamingText, Request, E> for T
Sourceยงimpl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
Sourceยงfn from_stimulus(other: U) -> T
fn from_stimulus(other: U) -> T
other
into Self
, while performing the appropriate scaling,
rounding and clamping.ยงimpl<S, T> FromStream<T> for S
impl<S, T> FromStream<T> for S
ยงfn from_stream(stream: impl Stream<Item = T> + Send + 'static) -> S
fn from_stream(stream: impl Stream<Item = T> + Send + 'static) -> S
ยงfn from_stream_unsync(stream: impl Stream<Item = T> + 'static) -> S
fn from_stream_unsync(stream: impl Stream<Item = T> + 'static) -> S
ยงimpl<T> Instrument for T
impl<T> Instrument for T
ยงfn instrument(self, span: Span) -> Instrumented<Self> โ
fn instrument(self, span: Span) -> Instrumented<Self> โ
Sourceยงimpl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
Sourceยงfn into_angle(self) -> U
fn into_angle(self) -> U
T
.Sourceยงimpl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
Sourceยงtype Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
parameters
when converting.Sourceยงfn into_cam16_unclamped(
self,
parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>,
) -> T
fn into_cam16_unclamped( self, parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>, ) -> T
self
into C
, using the provided parameters.Sourceยงimpl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
Sourceยงfn into_color(self) -> U
fn into_color(self) -> U
Sourceยงimpl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
Sourceยงfn into_color_unclamped(self) -> U
fn into_color_unclamped(self) -> U
Sourceยงimpl<T> IntoEither for T
impl<T> IntoEither for T
Sourceยงfn into_either(self, into_left: bool) -> Either<Self, Self> โ
fn into_either(self, into_left: bool) -> Either<Self, Self> โ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSourceยงfn into_either_with<F>(self, into_left: F) -> Either<Self, Self> โ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> โ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSourceยงimpl<T> IntoStimulus<T> for T
impl<T> IntoStimulus<T> for T
Sourceยงfn into_stimulus(self) -> T
fn into_stimulus(self) -> T
self
into T
, while performing the appropriate scaling,
rounding and clamping.ยงimpl<T> Pointable for T
impl<T> Pointable for T
ยงimpl<T> Pointee for T
impl<T> Pointee for T
ยงimpl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
ยงimpl<T> SerializableKey for T
impl<T> SerializableKey for T
ยงimpl<T> StorageAccess<T> for T
impl<T> StorageAccess<T> for T
ยงfn as_borrowed(&self) -> &T
fn as_borrowed(&self) -> &T
ยงfn into_taken(self) -> T
fn into_taken(self) -> T
Sourceยงimpl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
Sourceยงtype Error = <C as TryFromComponents<T>>::Error
type Error = <C as TryFromComponents<T>>::Error
try_into_colors
fails to cast.Sourceยงfn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
Sourceยงimpl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
Sourceยงfn try_into_color(self) -> Result<U, OutOfBounds<U>>
fn try_into_color(self) -> Result<U, OutOfBounds<U>>
OutOfBounds
error is returned which contains
the unclamped color. Read more