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
/// Parameter for [`ReflectEq`].
#[derive(Debug, Default)]
pub struct ReflectEqMode {
    /// When `true`, `NaN` values are considered equal to each other.
    pub nan_equal: bool,
    _non_exhausitve: (),
}

impl ReflectEqMode {
    /// Default equality, similar to `#[derive(PartialEq)]`.
    pub fn default() -> ReflectEqMode {
        Default::default()
    }

    /// Equality where float `NaN` values are considered equal to each other.
    ///
    /// Useful in tests.
    pub fn nan_equal() -> ReflectEqMode {
        ReflectEqMode {
            nan_equal: true,
            ..Default::default()
        }
    }
}

/// Special version of eq.
///
/// With `mode` [`ReflectEqMode::default()`], should be equivalent
/// to `#[derive(PartialEq)]`.
pub trait ReflectEq {
    /// Perform the equality comparison.
    fn reflect_eq(&self, that: &Self, mode: &ReflectEqMode) -> bool;
}