Struct token_cell::core::TokenCell
source · 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>
pub fn into_inner(self) -> T
Methods from Deref<Target = UnsafeCell<T>>§
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.
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
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);
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,
Constructs a new cell using
token
as its key.source§fn try_guard<'l>(
&'l self,
token: &'l Token
) -> Result<TokenGuard<'l, T, Token>, <Token as TokenTrait>::ComparisonError>
fn try_guard<'l>( &'l self, token: &'l Token ) -> Result<TokenGuard<'l, T, Token>, <Token as TokenTrait>::ComparisonError>
Attempts to construct a guard which
Deref
s to the inner data,
but also allows recovering the Token
.source§fn try_borrow<'l>(
&'l self,
token: &'l Token
) -> Result<&'l T, Token::ComparisonError>
fn try_borrow<'l>( &'l self, token: &'l Token ) -> Result<&'l T, Token::ComparisonError>
Attempts to borrow the inner data. Read more
source§fn try_guard_mut<'l>(
&'l self,
token: &'l mut Token
) -> Result<TokenGuardMut<'l, T, Token>, <Token as TokenTrait>::ComparisonError>
fn try_guard_mut<'l>( &'l self, token: &'l mut Token ) -> Result<TokenGuardMut<'l, T, Token>, <Token as TokenTrait>::ComparisonError>
Attempts to construct a guard which
DerefMut
s to the inner data,
but also allows recovering the Token
.source§fn try_borrow_mut<'l>(
&'l self,
token: &'l mut Token
) -> Result<&'l mut T, Token::ComparisonError>
fn try_borrow_mut<'l>( &'l self, token: &'l mut Token ) -> Result<&'l mut T, Token::ComparisonError>
Attempts to borrow the inner data mutably. Read more
source§fn map<'a, U, F: FnOnce(TokenGuard<'a, T, Token>) -> U>(
&'a self,
f: F
) -> TokenMap<'a, T, U, F, Self, Token>
fn map<'a, U, F: FnOnce(TokenGuard<'a, T, Token>) -> U>( &'a self, f: F ) -> TokenMap<'a, T, U, F, Self, Token>
Constructs a lazy computation that can then be applied using the token.
source§fn map_mut<'a, U, F: FnOnce(TokenGuardMut<'a, T, Token>) -> U>(
&'a self,
f: F
) -> TokenMapMut<'a, T, U, F, Self, Token>
fn map_mut<'a, U, F: FnOnce(TokenGuardMut<'a, T, Token>) -> U>( &'a self, f: F ) -> TokenMapMut<'a, T, U, F, Self, Token>
Constructs a lazy computation that can then be applied using the token.