pub trait Cas: Sync + Send {
// Required methods
fn current<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Option<Vec<u8>>, Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn swap<'life0, 'async_trait>(
&'life0 self,
value: Vec<u8>,
) -> Pin<Box<dyn Future<Output = Result<(), SwapError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn bucket_rep<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = u32> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn key<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = String> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
}
Expand description
Cas
trait describes the interface a key value compare and swap implementor must fulfill.
current
is expected to get the current value for the key associated with the CAS operation
while also starting what is needed to ensure the value to be replaced will not have mutated
between the time of calling current
and swap
. For example, a get from a backend store
may provide the caller with an etag (a version stamp), which can be used with an if-match
header to ensure the version updated is the version that was read (optimistic concurrency).
Rather than an etag, one could start a transaction, if supported by the backing store, which
would provide atomicity.
swap
is expected to replace the old value with the new value respecting the atomicity of the
operation. If there was no key / value with the given key in the store, the swap
operation
should insert the key and value, disallowing an update.