Skip to main content

TypedReducer

Trait TypedReducer 

Source
pub trait TypedReducer: Send + Sync {
    type Value: Serialize + DeserializeOwned + Send + Sync;

    // Required method
    fn reduce(&self, current: Self::Value, incoming: Self::Value) -> Self::Value;
}
Available on crate feature graph only.
Expand description

Trait for defining custom merge strategies for state values.

Implementations define how two values of the same type should be combined when parallel tasks produce outputs for the same state key, or when state updates need to be merged.

§Type Bounds

The associated Value type must be serializable, deserializable, and thread-safe (Send + Sync).

Required Associated Types§

Source

type Value: Serialize + DeserializeOwned + Send + Sync

The value type this reducer operates on.

Required Methods§

Source

fn reduce(&self, current: Self::Value, incoming: Self::Value) -> Self::Value

Merge two values. Called when parallel tasks produce outputs for the same state key.

§Arguments
  • current - The existing value in state
  • incoming - The new value to merge in
§Returns

The merged result of the two values.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§