Struct loom::cell::UnsafeCell

source ·
pub struct UnsafeCell<T: ?Sized> { /* private fields */ }
Expand description

A checked version of std::cell::UnsafeCell.

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 fn new(data: T) -> UnsafeCell<T>

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

source

pub fn into_inner(self) -> T

Unwraps the value.

source§

impl<T: ?Sized> UnsafeCell<T>

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

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

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. 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.

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. 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.

Trait Implementations§

source§

impl<T: Debug + ?Sized> Debug for UnsafeCell<T>

source§

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

Formats the value using the given formatter. Read more
source§

impl<T: Default> Default for UnsafeCell<T>

source§

fn default() -> UnsafeCell<T>

Returns the “default value” for a type. Read more
source§

impl<T> From<T> for UnsafeCell<T>

source§

fn from(src: T) -> UnsafeCell<T>

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<T> !Freeze for UnsafeCell<T>

§

impl<T> !RefUnwindSafe for UnsafeCell<T>

§

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

§

impl<T> !Sync for UnsafeCell<T>

§

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

§

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

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<!> for T

source§

fn from(t: !) -> T

Converts to this type from the input type.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

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

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

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.
source§

impl<T> WithSubscriber for T

source§

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
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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