• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /// Parameter for [`ReflectEq`].
2 #[derive(Debug, Default)]
3 pub struct ReflectEqMode {
4     /// When `true`, `NaN` values are considered equal to each other.
5     pub nan_equal: bool,
6     _non_exhausitve: (),
7 }
8 
9 impl ReflectEqMode {
10     /// Default equality, similar to `#[derive(PartialEq)]`.
default() -> ReflectEqMode11     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.
nan_equal() -> ReflectEqMode18     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)]`.
30 pub trait ReflectEq {
31     /// Perform the equality comparison.
reflect_eq(&self, that: &Self, mode: &ReflectEqMode) -> bool32     fn reflect_eq(&self, that: &Self, mode: &ReflectEqMode) -> bool;
33 }
34