Struct SyncUnsafeCell

#[repr(transparent)]
pub struct SyncUnsafeCell<T: ?Sized> { pub(in ::cell) value: UnsafeCell<T> }

UnsafeCell, but Sync.

This is just an UnsafeCell, except it implements Sync if T implements Sync.

UnsafeCell doesn't implement Sync, to prevent accidental mis-use. You can use SyncUnsafeCell instead of UnsafeCell to allow it to be shared between threads, if that's intentional. Providing proper synchronization is still the task of the user, making this type just as unsafe to use.

See UnsafeCell for details.

Fields

value: UnsafeCell<T>

Implementations

impl<T> SyncUnsafeCell<T>

const fn new(value: T) -> Self

Constructs a new instance of SyncUnsafeCell which will wrap the specified value.

const fn into_inner(self) -> T

Unwraps the value, consuming the cell.

impl<T: ?Sized> SyncUnsafeCell<T>

const fn get(&self) -> *mut T

Gets a mutable pointer to the wrapped value.

This can be cast to a pointer of any kind. Ensure that the access is unique (no active references, mutable or not) when casting to &mut T, and ensure that there are no mutations or mutable aliases going on when casting to &T

const fn get_mut(&mut self) -> &mut T

Returns a mutable reference to the underlying data.

This call borrows the SyncUnsafeCell mutably (at compile-time) which guarantees that we possess the only reference.

const fn raw_get(this: *const Self) -> *mut T

Gets a mutable pointer to the wrapped value.

See UnsafeCell::get for details.

Trait Implementations

impl<T> From<T> for SyncUnsafeCell<T>

fn from(t: T) -> SyncUnsafeCell<T>

Creates a new SyncUnsafeCell<T> containing the given value.

impl<T: ?Sized + Sync> Sync for SyncUnsafeCell<T>

impl<T: ?Sized> Debug for SyncUnsafeCell<T>

fn fmt(&self, f: &mut Formatter<'_>) -> Result

impl<T: CoerceUnsized<U>, U> CoerceUnsized<SyncUnsafeCell<U>> for SyncUnsafeCell<T>

impl<T: DispatchFromDyn<U>, U> DispatchFromDyn<SyncUnsafeCell<U>> for SyncUnsafeCell<T>

impl<T: ~const Default> Default for SyncUnsafeCell<T>

fn default() -> SyncUnsafeCell<T>

Creates an SyncUnsafeCell, with the Default value for T.

Auto Trait Implementations

impl<T> !Freeze for SyncUnsafeCell<T>

impl<T> !RefUnwindSafe for SyncUnsafeCell<T>

impl<T> Send for SyncUnsafeCell<T> where UnsafeCell<T>: Send, T: ?Sized,

impl<T> Unpin for SyncUnsafeCell<T> where UnsafeCell<T>: Unpin, T: ?Sized,

impl<T> UnsafeUnpin for SyncUnsafeCell<T> where UnsafeCell<T>: UnsafeUnpin, T: ?Sized,

impl<T> UnwindSafe for SyncUnsafeCell<T> where UnsafeCell<T>: UnwindSafe, T: ?Sized,

Blanket Implementations

impl<T> Any for SyncUnsafeCell<T> where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for SyncUnsafeCell<T> where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for SyncUnsafeCell<T> where T: ?Sized,

fn borrow_mut(&mut self) -> &mut T

impl<T> From<T> for SyncUnsafeCell<T>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> From<never> for SyncUnsafeCell<T>

fn from(t: never) -> T

impl<T> SizeHint for SyncUnsafeCell<T> where T: ?Sized,

fn lower_bound(&self) -> usize
fn upper_bound(&self) -> Option<usize>

impl<T> SizedTypeProperties for SyncUnsafeCell<T>

impl<T, U> Into<U> for SyncUnsafeCell<T> where U: From<T>,

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom<U> for SyncUnsafeCell<T> where U: Into<T>,

type Error = Infallible;
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto<U> for SyncUnsafeCell<T> where U: TryFrom<T>,

type Error = <U as TryFrom<T>>::Error;
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>