Trait token_cell::core::TokenCellTrait
source · pub trait TokenCellTrait<T: ?Sized, Token: TokenTrait>: Sync {
// Required methods
fn new(inner: T, token: &Token) -> Self
where T: Sized;
fn try_guard<'l>(
&'l self,
token: &'l Token
) -> Result<TokenGuard<'l, T, Token>, Token::ComparisonError>;
fn try_borrow<'l>(
&'l self,
token: &'l Token
) -> Result<&'l T, Token::ComparisonError>;
fn try_guard_mut<'l>(
&'l self,
token: &'l mut Token
) -> Result<TokenGuardMut<'l, T, Token>, Token::ComparisonError>;
fn try_borrow_mut<'l>(
&'l self,
token: &'l mut Token
) -> Result<&'l mut T, Token::ComparisonError>;
// Provided methods
fn borrow<'l>(&'l self, token: &'l Token) -> &'l T
where Token::ComparisonError: Debug { ... }
fn borrow_mut<'l>(&'l self, token: &'l mut Token) -> &'l mut T
where Token::ComparisonError: Debug { ... }
fn map<'a, U, F: FnOnce(TokenGuard<'a, T, Token>) -> U>(
&'a self,
f: F
) -> TokenMap<'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> { ... }
}
Required Methods§
sourcefn 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.
sourcefn try_guard<'l>(
&'l self,
token: &'l Token
) -> Result<TokenGuard<'l, T, Token>, Token::ComparisonError>
fn try_guard<'l>( &'l self, token: &'l Token ) -> Result<TokenGuard<'l, T, Token>, Token::ComparisonError>
Attempts to construct a guard which Deref
s to the inner data,
but also allows recovering the Token
.
sourcefn 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.
This only fails if the wrong token was used as a key, provided that Token
has a runtime comparison.
sourcefn try_guard_mut<'l>(
&'l self,
token: &'l mut Token
) -> Result<TokenGuardMut<'l, T, Token>, Token::ComparisonError>
fn try_guard_mut<'l>( &'l self, token: &'l mut Token ) -> Result<TokenGuardMut<'l, T, Token>, Token::ComparisonError>
Attempts to construct a guard which DerefMut
s to the inner data,
but also allows recovering the Token
.
sourcefn 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.
This only fails if the wrong token was used as a key, provided that Token
has a runtime comparison.
Provided Methods§
sourcefn borrow<'l>(&'l self, token: &'l Token) -> &'l Twhere
Token::ComparisonError: Debug,
fn borrow<'l>(&'l self, token: &'l Token) -> &'l Twhere Token::ComparisonError: Debug,
Borrows the inner data, panicking if the wrong token was used as key.
sourcefn borrow_mut<'l>(&'l self, token: &'l mut Token) -> &'l mut Twhere
Token::ComparisonError: Debug,
fn borrow_mut<'l>(&'l self, token: &'l mut Token) -> &'l mut Twhere Token::ComparisonError: Debug,
Borrows the inner data mutably, panicking if the wrong token was used as key.
sourcefn 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.
sourcefn 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.