Trait Token

Source
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.

Required Associated Types§

Source

type Id: Clone + Eq + TokenId

Id of the token.

Required Methods§

Source

fn id(&self) -> Self::Id

Returns the token id.

Source

fn is_unique(&mut self) -> bool

Returns true if the token is “unique”, see safety

Implementations on Foreign Types§

Source§

impl<T> Token for Box<T>

T must not be zero-sized.

Source§

type Id = PtrId<T>

Source§

fn id(&self) -> Self::Id

Source§

fn is_unique(&mut self) -> bool

Source§

impl<T> Token for Rc<T>

T must not be zero-sized.

Source§

type Id = PtrId<T>

Source§

fn id(&self) -> Self::Id

Source§

fn is_unique(&mut self) -> bool

Source§

impl<T> Token for Arc<T>

T must not be zero-sized.

Source§

type Id = PtrId<T>

Source§

fn id(&self) -> Self::Id

Source§

fn is_unique(&mut self) -> bool

Implementors§

Source§

impl Token for BoxToken

Source§

impl Token for DynamicToken

Source§

impl Token for LifetimeToken<'_>

Source§

type Id = ()

Source§

impl<T: ?Sized + 'static> Token for LocalTypeToken<T>

Source§

type Id = ()

Source§

impl<T: ?Sized + 'static> Token for TypeToken<T>

Source§

type Id = ()

Source§

impl<T: ?Sized> Token for RefToken<T>

Source§

type Id = PtrId<T>