Skip to main content

UnsafeTokenCellTrait

Trait UnsafeTokenCellTrait 

Source
pub trait UnsafeTokenCellTrait<T: ?Sized, Token: TokenTrait<ComparisonMaySpuriouslyEq = True>>: Sync {
    // Required methods
    unsafe fn try_guard<'l>(
        &'l self,
        token: &'l Token,
    ) -> Result<TokenGuard<'l, T, Token>, Token::ComparisonError>;
    unsafe fn try_borrow<'l>(
        &'l self,
        token: &'l Token,
    ) -> Result<&'l T, Token::ComparisonError>;
    unsafe fn try_guard_mut<'l>(
        &'l self,
        token: &'l mut Token,
    ) -> Result<TokenGuardMut<'l, T, Token>, Token::ComparisonError>;
    unsafe fn try_borrow_mut<'l>(
        &'l self,
        token: &'l mut Token,
    ) -> Result<&'l mut T, Token::ComparisonError>;

    // Provided methods
    unsafe fn borrow<'l>(&'l self, token: &'l Token) -> &'l T
       where Token::ComparisonError: Debug { ... }
    unsafe fn borrow_mut<'l>(&'l self, token: &'l mut Token) -> &'l mut T
       where Token::ComparisonError: Debug { ... }
    unsafe fn map<'a, U, F: FnOnce(TokenGuard<'a, T, Token>) -> U>(
        &'a self,
        f: F,
    ) -> TokenMap<'a, T, U, F, Self, Token, True> { ... }
    unsafe fn map_mut<'a, U, F: FnOnce(TokenGuardMut<'a, T, Token>) -> U>(
        &'a self,
        f: F,
    ) -> TokenMapMut<'a, T, U, F, Self, Token, True> { ... }
}
Expand description

Common ways to interract with a TokenCell.

Note that while many functions document fallihle behaviours, this behaviour is only reachable for tokens that perform runtime check. These are identifiable by their TokenTrait::ComparisonError type not being core::convert::Infallible.

Required Methods§

Source

unsafe fn try_guard<'l>( &'l self, token: &'l Token, ) -> Result<TokenGuard<'l, T, Token>, Token::ComparisonError>

Attempts to construct a guard which Derefs to the inner data, but also allows recovering the Token.

§Safety

token must refer to the exact same instance of Token as that which was used to call [Self::new].

§Errors

If the token provides runtime checking and detects that self was constructed with another token.

If such an error is ever raised, it should be treated as a high priority bug in your application, as that would indicate that the safety requirement was not met, but was detected before Undefined Behaviour could be triggered.

Source

unsafe fn try_borrow<'l>( &'l self, token: &'l Token, ) -> Result<&'l T, Token::ComparisonError>

Attempts to borrow the inner data.

§Safety

token must refer to the exact same instance of Token as that which was used to call [Self::new].

§Errors

If the token provides runtime checking and detects that self was constructed with another token.

Source

unsafe fn try_guard_mut<'l>( &'l self, token: &'l mut Token, ) -> Result<TokenGuardMut<'l, T, Token>, Token::ComparisonError>

Attempts to construct a guard which DerefMuts to the inner data, but also allows recovering the Token.

§Safety

token must refer to the exact same instance of Token as that which was used to call [Self::new].

§Errors

If the token provides runtime checking and detects that self was constructed with another token.

Source

unsafe fn try_borrow_mut<'l>( &'l self, token: &'l mut Token, ) -> Result<&'l mut T, Token::ComparisonError>

Attempts to borrow the inner data mutably.

§Safety

token must refer to the exact same instance of Token as that which was used to call [Self::new].

§Errors

If the token provides runtime checking and detects that self was constructed with another token.

Provided Methods§

Source

unsafe fn borrow<'l>(&'l self, token: &'l Token) -> &'l T
where Token::ComparisonError: Debug,

Borrows the inner data, panicking if the wrong token was used as key.

§Safety

token must refer to the exact same instance of Token as that which was used to call [Self::new].

Source

unsafe fn borrow_mut<'l>(&'l self, token: &'l mut Token) -> &'l mut T
where Token::ComparisonError: Debug,

Borrows the inner data mutably, panicking if the wrong token was used as key.

§Safety

token must refer to the exact same instance of Token as that which was used to call [Self::new].

Source

unsafe fn map<'a, U, F: FnOnce(TokenGuard<'a, T, Token>) -> U>( &'a self, f: F, ) -> TokenMap<'a, T, U, F, Self, Token, True>

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

§Safety

token must refer to the exact same instance of Token as that which was used to call [Self::new].

Source

unsafe fn map_mut<'a, U, F: FnOnce(TokenGuardMut<'a, T, Token>) -> U>( &'a self, f: F, ) -> TokenMapMut<'a, T, U, F, Self, Token, True>

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

§Safety

token must refer to the exact same instance of Token as that which was used to call [Self::new].

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T: ?Sized, Token: TokenTrait<ComparisonMaySpuriouslyEq = True>> UnsafeTokenCellTrait<T, Token> for TokenCell<T, Token>