pub trait MergeOperator: Send + Sync {
// Required method
fn merge(
&self,
key: &Bytes,
existing_value: Option<Bytes>,
new_value: Bytes,
) -> Bytes;
// Provided method
fn merge_batch(
&self,
key: &Bytes,
existing_value: Option<Bytes>,
operands: &[Bytes],
) -> Bytes { ... }
}Expand description
Trait for merging existing values with new values.
Merge operators must be associative: merge(merge(a, b), c) == merge(a, merge(b, c)).
This ensures consistent merging behavior regardless of the order of operations.
Required Methods§
Provided Methods§
Sourcefn merge_batch(
&self,
key: &Bytes,
existing_value: Option<Bytes>,
operands: &[Bytes],
) -> Bytes
fn merge_batch( &self, key: &Bytes, existing_value: Option<Bytes>, operands: &[Bytes], ) -> Bytes
Merges a batch of operands with an optional existing value.
The default implementation applies pairwise merging. Implementations can override this for better performance by constructing a single merge result once for multiple input values.
§Arguments
key- The key associated with the values being mergedexisting_value- The current value stored in the database (if any)operands- A slice of operands to merge, ordered from oldest to newest