Skip to main content

Aggregator

Trait Aggregator 

Source
pub trait Aggregator:
    Send
    + Sync
    + Debug {
    type Input: Clone;
    type Output: Clone;
    type Accumulator: Clone + Serialize + for<'de> Deserialize<'de>;

    // Required methods
    fn new() -> Self
       where Self: Sized;
    fn update(&mut self, value: Self::Input) -> Result<()>;
    fn finalize(&self) -> Result<Self::Output>;
    fn accumulator(&self) -> Self::Accumulator;
    fn merge(&mut self, other: Self::Accumulator) -> Result<()>;
    fn reset(&mut self);
    fn count(&self) -> u64;

    // Provided methods
    fn update_batch(&mut self, values: &[Self::Input]) -> Result<()> { ... }
    fn is_empty(&self) -> bool { ... }
}
Expand description

Core trait for all aggregators

This trait defines the interface for incremental aggregation with support for:

  • Incremental updates (feed values one at a time)
  • Accumulator merging (for distributed processing)
  • State serialization (for persistence and recovery)

Required Associated Types§

Source

type Input: Clone

The type of values this aggregator accepts

Source

type Output: Clone

The type of the final aggregation result

Source

type Accumulator: Clone + Serialize + for<'de> Deserialize<'de>

The type of the internal accumulator state (must be serializable)

Required Methods§

Source

fn new() -> Self
where Self: Sized,

Create a new aggregator instance

Source

fn update(&mut self, value: Self::Input) -> Result<()>

Update the aggregator with a new value

Source

fn finalize(&self) -> Result<Self::Output>

Compute the final aggregation result

Source

fn accumulator(&self) -> Self::Accumulator

Get the current accumulator state (for serialization/merging)

Source

fn merge(&mut self, other: Self::Accumulator) -> Result<()>

Merge another accumulator into this one (for distributed processing)

Source

fn reset(&mut self)

Reset the aggregator to initial state

Source

fn count(&self) -> u64

Get the number of values processed so far

Provided Methods§

Source

fn update_batch(&mut self, values: &[Self::Input]) -> Result<()>

Update with multiple values at once

Source

fn is_empty(&self) -> bool

Check if the aggregator has processed any values

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§