Skip to main content

AtomicInsert

Trait AtomicInsert 

Source
pub trait AtomicInsert<T>: KvStore<T> {
    // Required method
    fn insert_if_absent<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 str,
        value: T,
        ttl: Duration,
    ) -> Pin<Box<dyn Future<Output = Result<bool, StoreError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
}
Expand description

Backends that can atomically insert a value only if no value is currently stored under key implement this.

This is the complement of AtomicConsume, not a duplicate of it: AtomicConsume is for values the server creates and later atomically fetches-and-removes (an authorization code, say — the key is only ever seen after this server put it there). AtomicInsert is for values whose key is supplied by the caller and was never stored by this server first — the shape a replay guard needs, e.g. a DPoP proof’s jti, which a client generates and this server has never seen before the first time it’s presented.

Required Methods§

Source

fn insert_if_absent<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, value: T, ttl: Duration, ) -> Pin<Box<dyn Future<Output = Result<bool, StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Inserts value under key only if key does not already hold a value. Returns Ok(true) if the insert happened (the key was fresh) and Ok(false) if a value was already present (the key was already claimed — e.g. a replay). Must be a single atomic operation: a check-then-set built from get followed by set is a TOCTOU race that defeats the entire purpose of a replay guard.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§