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>

source

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

source§

impl<T: Sized, Token: TokenTrait> TokenCell<T, Token>

source

pub fn into_inner(self) -> T

Methods from Deref<Target = UnsafeCell<T>>§

1.0.0 · source

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

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> Deref for TokenCell<T, Token>

§

type Target = UnsafeCell<T>

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<T: ?Sized, Token: TokenTrait> DerefMut for TokenCell<T, Token>

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
source§

impl<T: ?Sized, Token: TokenTrait> TokenCellTrait<T, Token> for TokenCell<T, Token>

source§

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>

Attempts to construct a guard which Derefs 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>

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>

Attempts to construct a guard which DerefMuts 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>

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>

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>

Constructs a lazy computation that can then be applied using the token.
source§

impl<T: ?Sized, Token: TokenTrait> Sync for TokenCell<T, Token>

Auto Trait Implementations§

§

impl<T, Token> !RefUnwindSafe for TokenCell<T, Token>

§

impl<T: ?Sized, Token> Send for TokenCell<T, Token>where T: Send, <Token as TokenTrait>::Identifier: Send,

§

impl<T: ?Sized, Token> Unpin for TokenCell<T, Token>where T: Unpin, <Token as TokenTrait>::Identifier: Unpin,

§

impl<T: ?Sized, Token> UnwindSafe for TokenCell<T, Token>where T: UnwindSafe, <Token as TokenTrait>::Identifier: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.