protobuf/reflect/reflect_eq.rs
1/// Parameter for [`ReflectEq`].
2#[derive(Debug, Default)]
3pub struct ReflectEqMode {
4 /// When `true`, `NaN` values are considered equal to each other.
5 pub nan_equal: bool,
6 _non_exhausitve: (),
7}
8
9impl ReflectEqMode {
10 /// Default equality, similar to `#[derive(PartialEq)]`.
11 pub fn default() -> ReflectEqMode {
12 Default::default()
13 }
14
15 /// Equality where float `NaN` values are considered equal to each other.
16 ///
17 /// Useful in tests.
18 pub fn nan_equal() -> ReflectEqMode {
19 ReflectEqMode {
20 nan_equal: true,
21 ..Default::default()
22 }
23 }
24}
25
26/// Special version of eq.
27///
28/// With `mode` [`ReflectEqMode::default()`], should be equivalent
29/// to `#[derive(PartialEq)]`.
30pub trait ReflectEq {
31 /// Perform the equality comparison.
32 fn reflect_eq(&self, that: &Self, mode: &ReflectEqMode) -> bool;
33}