Skip to main content

trustformers_debug/streaming_debugger/
aggregationfunction_traits.rs

1//! # AggregationFunction - Trait Implementations
2//!
3//! This module contains trait implementations for `AggregationFunction`.
4//!
5//! ## Implemented Traits
6//!
7//! - `Hash`
8//! - `Eq`
9//! - `PartialEq`
10//!
11//! 🤖 Generated with [SplitRS](https://github.com/cool-japan/splitrs)
12
13use super::types::*;
14use std::mem;
15
16impl std::hash::Hash for AggregationFunction {
17    fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
18        mem::discriminant(self).hash(state);
19        match self {
20            AggregationFunction::Percentile(p) => {
21                p.to_bits().hash(state);
22            },
23            AggregationFunction::Custom(s) => s.hash(state),
24            _ => {},
25        }
26    }
27}
28
29impl Eq for AggregationFunction {}
30
31impl PartialEq for AggregationFunction {
32    fn eq(&self, other: &Self) -> bool {
33        match (self, other) {
34            (AggregationFunction::Percentile(a), AggregationFunction::Percentile(b)) => {
35                a.to_bits() == b.to_bits()
36            },
37            (AggregationFunction::Custom(a), AggregationFunction::Custom(b)) => a == b,
38            _ => mem::discriminant(self) == mem::discriminant(other),
39        }
40    }
41}