Trait TokenTrait

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

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§