pub trait TokenTrait: Sized {
    type ConstructionError;
    type RunError;
    type Identifier;
    type ComparisonError;

    // Required methods
    fn new() -> Result<Self, Self::ConstructionError>;
    fn with_token<R, F: FnOnce(Self) -> R>(f: F) -> Result<R, Self::RunError>;
    fn identifier(&self) -> Self::Identifier;
    fn compare(
        &self,
        id: &Self::Identifier
    ) -> Result<(), Self::ComparisonError>;
}
Expand description

A trait for tokens

Required Associated Types§

Required Methods§

source

fn new() -> Result<Self, Self::ConstructionError>

Constructs a new Token.

source

fn with_token<R, F: FnOnce(Self) -> R>(f: F) -> Result<R, Self::RunError>

Constructs a new Token, and provides it to the closure.

While this should allow to provide a traitified version of ghost-cell, it seems the compiler only detects the lifetime invariance with inherent methods.

source

fn identifier(&self) -> Self::Identifier

Returns the Token’s identifier, which cells may store to allow comparison.

source

fn compare(&self, id: &Self::Identifier) -> Result<(), Self::ComparisonError>

Allows the cell to compare its identifier to the Token.

Implementors§