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§
Required Methods§
Sourcefn insert_if_absent(
&self,
key: &[u8],
value: &[u8],
) -> Result<bool, Self::Error>
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.