pub unsafe trait Token {
type Id: Clone + Eq + TokenId;
// Required methods
fn id(&self) -> Self::Id;
fn is_unique(&mut self) -> bool;
}
Expand description
Token type to be used with TokenRefCell
.
It defines an Id
type, which is stored in the cell and used to check its accesses.
TokenId
bound is a hidden trait used to hack Rust type system in order to allow
TokenRefCell
being defined with #[repr(transparent)]
when Id
is ()
.
It can be implemented using hidden impl_token_id!
macro, for example
impl_token_id!(PtrId<T: ?Sized>)
.
This bound is temporary and will be removed when Rust type system will allow
const expressions like size_of::<Tk>() == 0
to be used as generic parameter.
§Safety
If Token::is_unique
returns true, then there must be no other instances of the same token
type with Token::id
returning the same id as the current “unique” instance;
if the token type is neither Send
nor Sync
, this unicity constraint is relaxed to the
current thread.
Token implementations can rely on the fact that TokenRefCell
,
Ref
, RefMut
, Reborrow
,
and ReborrowMut
are invariant on their Tk: Token
generic parameter.