Skip to main content

CrdtState

Trait CrdtState 

Source
pub trait CrdtState:
    Send
    + Sync
    + 'static {
    // Required methods
    fn as_any(&self) -> &dyn Any;
    fn apply(&mut self, op: &CrdtOp) -> Result<(), FnError>;
    fn merge(&mut self, other: &dyn CrdtState) -> Result<(), FnError>;
    fn value(&self) -> Result<ScalarValue, FnError>;
    fn persist(&self) -> Result<Vec<u8>, FnError>;
}
Expand description

Per-instance CRDT state.

'static is required so CrdtState::as_any can downcast safely in merge implementations to access the concrete other-state.

Required Methods§

Source

fn as_any(&self) -> &dyn Any

Return &dyn Any for safe downcasting in merge implementations.

Implementations should expose as_any with the one-liner fn as_any(&self) -> &dyn std::any::Any { self }.

Source

fn apply(&mut self, op: &CrdtOp) -> Result<(), FnError>

Apply an operation to this state.

§Errors

Returns FnError on application failure.

Source

fn merge(&mut self, other: &dyn CrdtState) -> Result<(), FnError>

Merge other into self (must be associative + commutative).

§Errors

Returns FnError on merge failure.

Source

fn value(&self) -> Result<ScalarValue, FnError>

Query the current logical value.

§Errors

Returns FnError if the value cannot be computed.

Source

fn persist(&self) -> Result<Vec<u8>, FnError>

Serialize for persistence.

§Errors

Returns FnError on serialization failure.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§