Skip to main content

CompareAndSwap

Trait CompareAndSwap 

Source
pub trait CompareAndSwap {
    type Error: Debug;

    // Required methods
    fn insert_if_absent(
        &self,
        key: &[u8],
        value: &[u8],
    ) -> Result<bool, Self::Error>;
    fn compare_and_set(
        &self,
        key: &[u8],
        expected: &[u8],
        new_value: &[u8],
    ) -> Result<bool, Self::Error>;
    fn delete_if_match(
        &self,
        key: &[u8],
        expected: &[u8],
    ) -> Result<bool, Self::Error>;
}
Expand description

Compare-and-swap trait for storage backends

This trait abstracts the CAS operation for different storage implementations. SochDB’s storage layer should implement this for durable claims.

Required Associated Types§

Source

type Error: Debug

Type of error returned

Required Methods§

Source

fn insert_if_absent( &self, key: &[u8], value: &[u8], ) -> Result<bool, Self::Error>

Insert a key-value pair only if the key doesn’t exist

Returns Ok(true) if inserted, Ok(false) if key exists, Err on failure.

Source

fn compare_and_set( &self, key: &[u8], expected: &[u8], new_value: &[u8], ) -> Result<bool, Self::Error>

Update a value only if the current value matches expected

Returns Ok(true) if updated, Ok(false) if mismatch, Err on failure.

Source

fn delete_if_match( &self, key: &[u8], expected: &[u8], ) -> Result<bool, Self::Error>

Delete a key only if the current value matches expected

Returns Ok(true) if deleted, Ok(false) if mismatch, Err on failure.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§