Skip to main content

UnsafeCellDeref

Trait UnsafeCellDeref 

Source
pub trait UnsafeCellDeref<'a, T>: SealedUnsafeCell {
    // Required methods
    unsafe fn deref_mut(self) -> &'a mut T;
    unsafe fn deref(self) -> &'a T;
    unsafe fn read(self) -> T
       where T: Copy;
}
Expand description

Extension trait for helper methods on UnsafeCell

Required Methods§

Source

unsafe fn deref_mut(self) -> &'a mut T

§Safety
  • The returned value must be unique and not alias any mutable or immutable references to the contents of the UnsafeCell.
  • At all times, you must avoid data races. If multiple threads have access to the same UnsafeCell, then any writes must have a proper happens-before relation to all other accesses or use atomics (UnsafeCell docs for reference).
Source

unsafe fn deref(self) -> &'a T

§Safety
  • For the lifetime 'a of the returned value you must not construct a mutable reference to the contents of the UnsafeCell.
  • At all times, you must avoid data races. If multiple threads have access to the same UnsafeCell, then any writes must have a proper happens-before relation to all other accesses or use atomics (UnsafeCell docs for reference).
Source

unsafe fn read(self) -> T
where T: Copy,

Returns a copy of the contained value.

§Safety
  • The UnsafeCell must not currently have a mutable reference to its content.
  • At all times, you must avoid data races. If multiple threads have access to the same UnsafeCell, then any writes must have a proper happens-before relation to all other accesses or use atomics (UnsafeCell docs for reference).

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<'a, T> UnsafeCellDeref<'a, T> for &'a UnsafeCell<T>

Source§

unsafe fn deref_mut(self) -> &'a mut T

Source§

unsafe fn deref(self) -> &'a T

Source§

unsafe fn read(self) -> T
where T: Copy,

Implementors§