shoulda_core/
epsilon_provider.rs

1use const_env::from_env;
2
3pub trait EpsilonProvider {
4    fn diff() -> f64;
5}
6
7#[from_env]
8const SHOULDA_EPSILON: f64 = 0.0001;
9
10pub struct EnvEpsilonProvider;
11
12impl EpsilonProvider for EnvEpsilonProvider {
13    fn diff() -> f64 {
14        SHOULDA_EPSILON
15    }
16}
17
18/// since only integers are stable as const generics, this accepts an integer that will be std::mem::transmuted to an f64 before being used
19/// once const generic floats are stabilized this will change to const N: f64
20pub struct ConstEpsilonProvider<const N: u64>;
21
22impl<const N: u64> EpsilonProvider for ConstEpsilonProvider<N> {
23    fn diff() -> f64 {
24        f64::from_bits(N)
25    }
26}