hyperloglog_rs/ones.rs
1//! This module provides a trait to define the ONE const for all unsigned
2//! types and the method is_one(). This is not a trait in the core library,
3//! but we are aware that it is available in other crates - we do not intend
4//! to use them as dependencies, as we want to keep the dependencies to the
5//! very bare minimum.
6
7pub trait One {
8 /// The one value for this type.
9 const ONE: Self;
10 /// Whether the value is one.
11 fn is_one(&self) -> bool;
12}
13
14macro_rules! impl_one {
15 ($($t:ty)*) => ($(
16 impl One for $t {
17 const ONE: Self = 1;
18 #[inline(always)]
19 fn is_one(&self) -> bool { *self == 1 }
20 }
21 )*)
22}
23
24impl_one! { u8 u16 u32 u64 u128 usize }
25
26macro_rules! impl_one_float {
27 ($($t:ty)*) => ($(
28 impl One for $t {
29 const ONE: Self = 1.0;
30 #[inline(always)]
31 fn is_one(&self) -> bool { *self == 1.0 }
32 }
33 )*)
34}
35
36impl_one_float! { f32 f64 }