1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#![allow(missing_docs)]
use serde::{Deserialize, Serialize};
use crate::{traits::Coalesce, Aggregate};
use super::{shared::Counter, shared::MinMax, Aggregators};
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct BytesContext {
pub count: Counter,
pub min_max_length: MinMax<usize>,
#[serde(skip)]
pub other_aggregators: Aggregators<[u8]>,
}
impl Aggregate<[u8]> for BytesContext {
fn aggregate(&mut self, value: &'_ [u8]) {
self.count.aggregate(value);
self.min_max_length.aggregate(&value.len());
self.other_aggregators.aggregate(value);
}
}
impl Coalesce for BytesContext {
fn coalesce(&mut self, other: Self)
where
Self: Sized,
{
self.count.coalesce(other.count);
self.min_max_length.coalesce(other.min_max_length);
self.other_aggregators.coalesce(other.other_aggregators);
}
}
impl PartialEq for BytesContext {
fn eq(&self, other: &Self) -> bool {
self.count == other.count && self.min_max_length == other.min_max_length
}
}