pub struct TokenCell<T: ?Sized, Token: TokenTrait> { /* private fields */ }
Expand description
A Cell that shifts the management of access permissions to its inner value onto a Token
.
Implementations§
Source§impl<T: ?Sized, Token: TokenTrait> TokenCell<T, Token>
impl<T: ?Sized, Token: TokenTrait> TokenCell<T, Token>
Source§impl<T: Sized, Token: TokenTrait> TokenCell<T, Token>
impl<T: Sized, Token: TokenTrait> TokenCell<T, Token>
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Unwraps the value from the cell.
Full ownership of the cell is sufficient proof that the inner value can be recovered.
Methods from Deref<Target = UnsafeCell<T>>§
Sourcepub unsafe fn replace(&self, value: T) -> T
🔬This is a nightly-only experimental API. (unsafe_cell_access
)
pub unsafe fn replace(&self, value: T) -> T
unsafe_cell_access
)Replace the value in this UnsafeCell
and return the old value.
§Safety
The caller must take care to avoid aliasing and data races.
- It is Undefined Behavior to allow calls to race with any other access to the wrapped value.
- It is Undefined Behavior to call this while any other reference(s) to the wrapped value are alive.
§Examples
#![feature(unsafe_cell_access)]
use std::cell::UnsafeCell;
let uc = UnsafeCell::new(5);
let old = unsafe { uc.replace(10) };
assert_eq!(old, 5);
1.0.0 · Sourcepub fn get(&self) -> *mut T
pub fn get(&self) -> *mut T
Gets a mutable pointer to the wrapped value.
This can be cast to a pointer of any kind. When creating references, you must uphold the aliasing rules; see the type-level docs for more discussion and caveats.
§Examples
use std::cell::UnsafeCell;
let uc = UnsafeCell::new(5);
let five = uc.get();
1.50.0 · Sourcepub fn get_mut(&mut self) -> &mut T
pub fn get_mut(&mut self) -> &mut T
Returns a mutable reference to the underlying data.
This call borrows the UnsafeCell
mutably (at compile-time) which
guarantees that we possess the only reference.
§Examples
use std::cell::UnsafeCell;
let mut c = UnsafeCell::new(5);
*c.get_mut() += 1;
assert_eq!(*c.get_mut(), 6);
Sourcepub unsafe fn as_ref_unchecked(&self) -> &T
🔬This is a nightly-only experimental API. (unsafe_cell_access
)
pub unsafe fn as_ref_unchecked(&self) -> &T
unsafe_cell_access
)Get a shared reference to the value within the UnsafeCell
.
§Safety
- It is Undefined Behavior to call this while any mutable reference to the wrapped value is alive.
- Mutating the wrapped value while the returned reference is alive is Undefined Behavior.
§Examples
#![feature(unsafe_cell_access)]
use std::cell::UnsafeCell;
let uc = UnsafeCell::new(5);
let val = unsafe { uc.as_ref_unchecked() };
assert_eq!(val, &5);
Sourcepub unsafe fn as_mut_unchecked(&self) -> &mut T
🔬This is a nightly-only experimental API. (unsafe_cell_access
)
pub unsafe fn as_mut_unchecked(&self) -> &mut T
unsafe_cell_access
)Get an exclusive reference to the value within the UnsafeCell
.
§Safety
- It is Undefined Behavior to call this while any other reference(s) to the wrapped value are alive.
- Mutating the wrapped value through other means while the returned reference is alive is Undefined Behavior.
§Examples
#![feature(unsafe_cell_access)]
use std::cell::UnsafeCell;
let uc = UnsafeCell::new(5);
unsafe { *uc.as_mut_unchecked() += 1; }
assert_eq!(uc.into_inner(), 6);
Trait Implementations§
Source§impl<T: ?Sized, Token: TokenTrait> TokenCellTrait<T, Token> for TokenCell<T, Token>
impl<T: ?Sized, Token: TokenTrait> TokenCellTrait<T, Token> for TokenCell<T, Token>
Source§fn new(inner: T, token: &Token) -> Selfwhere
T: Sized,
fn new(inner: T, token: &Token) -> Selfwhere
T: Sized,
token
as its key.