hyperloglog_rs/
zeros.rs

1//! This module provides a trait to define the ZERO const for all unsigned
2//! types and the method is_zero(). 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 Zero {
8    /// The zero value for this type.
9    const ZERO: Self;
10    /// Whether the value is zero.
11    fn is_zero(&self) -> bool;
12}
13
14macro_rules! impl_zero {
15    ($($t:ty)*) => ($(
16        impl Zero for $t {
17            const ZERO: Self = 0;
18            #[inline(always)]
19            fn is_zero(&self) -> bool { *self == 0 }
20        }
21    )*)
22}
23
24impl_zero! { u8 u16 u32 u64 u128 usize }