pub struct UnsafeCell<T> { /* private fields */ }
Available on non-loom only.
Expand description

A variant of core::cell::UnsafeCell that may be checked when Loom model checking is enabled.

This type is similar to core::cell::UnsafeCell, except when the cfg(loom) cfg flag is enabled, it is replaced with a variant that participates in Loom model checking. See loom::cell::UnsafeCell for details on this.

When cfg(loom) is not set, this type is essentially a core::cell::UnsafeCell, but with an API that matches that of the checked Loom cell.

Instead of providing a get() API, this version of UnsafeCell provides with and with_mut. Both functions take a closure in order to track the start and end of the access to the underlying cell.

Implementations§

source§

impl<T> UnsafeCell<T>

source

pub const fn new(data: T) -> Self

Construct a new instance of UnsafeCell which will wrap the specified value.

source

pub fn with<F, R>(&self, f: F) -> R
where F: FnOnce(*const T) -> R,

Get an immutable pointer to the wrapped value.

Panics

When running under loom, this function will panic if the access is not valid under the Rust memory model.

source

pub fn with_mut<F, R>(&self, f: F) -> R
where F: FnOnce(*mut T) -> R,

Get a mutable pointer to the wrapped value.

Panics

When running under loom, this function will panic if the access is not valid under the Rust memory model.

source

pub fn get(&self) -> ConstPtr<T>

Get an immutable pointer to the wrapped value.

This function returns a ConstPtr guard, which is analogous to a *const T, but tracked by Loom when the cfg(loom) cfg flag is enabled. As long as the returned ConstPtr exists, Loom will consider the cell to be accessed immutably.

This means that any mutable accesses (e.g. calls to with_mut or get_mut) while the returned guard is live will result in a panic.

Panics

This function will panic if the access is not valid under the Rust memory model, if cfg(loom) is enabled.

source

pub fn get_mut(&self) -> MutPtr<T>

Get a mutable pointer to the wrapped value.

This function returns a MutPtr guard, which is analogous to a *mut T, but tracked by Loom when the cfg(loom) cfg flag is enabled. As long as the returned MutPtr exists, Loom will consider the cell to be accessed mutably.

This means that any concurrent mutable or immutable accesses (e.g. calls to with, with_mut, get, or get_mut) while the returned guard is live will result in a panic.

Panics

This function will panic if the access is not valid under the Rust memory model, if cfg(loom) is enabled.

Trait Implementations§

source§

impl<T: Debug> Debug for UnsafeCell<T>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for UnsafeCell<T>

§

impl<T> Send for UnsafeCell<T>
where T: Send,

§

impl<T> !Sync for UnsafeCell<T>

§

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

§

impl<T> UnwindSafe for UnsafeCell<T>
where T: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

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

source§

fn into(self) -> U

Calls U::from(self).

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

source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
source§

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

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more