rstmt_core/freq/traits/
frequency.rs

1/*
2    appellation: frequency <module>
3    authors: @FL03
4*/
5
6/// [`RawFrequency`] defines an interface for all raw Frequency types.
7///
8/// **note:** This trait is sealed and cannot be implemented outside of this crate.
9pub trait RawFrequency: Send + Sync + core::fmt::Debug + core::fmt::Display {
10    private!();
11}
12/// The [`FrequencyNum`] trait extends the [`RawFrequency`] trait with additional numeric operations
13/// and traits.
14pub trait FrequencyNum: RawFrequency
15where
16    Self: 'static
17        + Copy
18        + Eq
19        + Default
20        + PartialEq
21        + PartialOrd
22        + core::ops::Add<Output = Self>
23        + core::ops::Sub<Output = Self>
24        + core::ops::Mul<Output = Self>
25        + core::ops::Div<Output = Self>
26        + core::ops::Rem<Output = Self>
27        + core::ops::Neg<Output = Self>
28        + core::ops::Not<Output = Self>
29        + core::ops::AddAssign
30        + core::ops::SubAssign
31        + core::ops::MulAssign
32        + core::ops::DivAssign
33        + core::ops::RemAssign
34        + num_traits::NumRef
35        + num_traits::FromPrimitive
36        + num_traits::ToPrimitive
37        + num_traits::Signed
38        + num_traits::Zero
39        + num_traits::One,
40{
41}
42
43/*
44 ************* Implementations *************
45*/
46
47macro_rules! impl_raw_frequency {
48    ($($t:ty),* $(,)?) => {
49        $(
50            impl_raw_frequency!(@impl $t);
51        )*
52    };
53    (@impl $t:ty) => {
54        impl RawFrequency for $t {
55            seal!();
56        }
57    };
58}
59
60impl_raw_frequency!(
61    u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize, f32, f64
62);
63
64impl<T> FrequencyNum for T where
65    T: RawFrequency
66        + 'static
67        + Copy
68        + Default
69        + Eq
70        + PartialEq
71        + PartialOrd
72        + core::ops::Add<Output = Self>
73        + core::ops::Sub<Output = Self>
74        + core::ops::Mul<Output = Self>
75        + core::ops::Div<Output = Self>
76        + core::ops::Rem<Output = Self>
77        + core::ops::Neg<Output = Self>
78        + core::ops::Not<Output = Self>
79        + core::ops::AddAssign
80        + core::ops::SubAssign
81        + core::ops::MulAssign
82        + core::ops::DivAssign
83        + core::ops::RemAssign
84        + num_traits::NumRef
85        + num_traits::FromPrimitive
86        + num_traits::ToPrimitive
87        + num_traits::Signed
88        + num_traits::Zero
89        + num_traits::One
90{
91}