Skip to main content

ConsistencyTokenStore

Trait ConsistencyTokenStore 

Source
pub trait ConsistencyTokenStore:
    Send
    + Sync
    + Debug {
    // Required methods
    fn get(&self) -> String;
    fn set(&self, token: String);

    // Provided methods
    fn replace(&self, presented: &str, answered: String) { ... }
    fn remove(&self, refused: &str) { ... }
}
Expand description

Holds the consistency token a client presents. The client reads it before each attempt of an authenticated call, replaces it with the token an answer carries, and removes one the API refused.

It must be Send + Sync on every target, as Client is, so that a client can live in a browser app’s reactive state. In a browser a store therefore holds the token in something Send + Sync, such as a Mutex or a reactive signal, and copies it to web_sys::Storage from there if it is to outlive the page, rather than wrapping the Storage itself, which isn’t Send. Its methods are synchronous, and are called with no lock of the client’s held.

Required Methods§

Source

fn get(&self) -> String

The token held; empty when none is.

Source

fn set(&self, token: String)

Replaces the token held with token.

Provided Methods§

Source

fn replace(&self, presented: &str, answered: String)

Replaces the token held with answered, the token the answer to a call that presented presented (empty for none) carried. A store that holds a token other than presented by then was written by a concurrent call in between, and may keep one or the other as it sees fit; the default sets answered, so the token answered last is kept.

Source

fn remove(&self, refused: &str)

Forgets refused, a token the API refused to read, if it is still the one held; a token that replaced it in the meantime stays. The default reads and then sets the token, so it can lose a token set in between; a store that can do it at once should.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§