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
use const_env::from_env; pub trait EpsilonProvider { fn diff() -> f64; } #[from_env] const SHOULDA_EPSILON: f64 = 0.0001; pub struct EnvEpsilonProvider; impl EpsilonProvider for EnvEpsilonProvider { fn diff() -> f64 { SHOULDA_EPSILON } } /// since only integers are stable as const generics, this accepts an integer that will be std::mem::transmuted to an f64 before being used /// once const generic floats are stabilized this will change to const N: f64 pub struct ConstEpsilonProvider<const N: u64>; impl<const N: u64> EpsilonProvider for ConstEpsilonProvider<N> { fn diff() -> f64 { unsafe { std::mem::transmute(N) } } }