concision_core/traits/misc/
toggle.rs

1/*
2    Appellation: toggle <module>
3    Contrib: FL03 <jo3mccain@icloud.com>
4*/
5
6pub trait Toggle: 'static {}
7
8pub trait OfType {
9    fn of<T>() -> bool
10    where
11        T: 'static,
12        Self: 'static,
13    {
14        core::any::TypeId::of::<T>() == core::any::TypeId::of::<Self>()
15    }
16}
17
18/*
19 ************* Implementations *************
20*/
21impl<T> OfType for T {}
22
23macro_rules! impl_toggle {
24    ($($scope:ident$(<$T:ident>)?),* $(,)?) => {
25        $(impl_toggle!(@impl $scope$(<$T>)?);)*
26    };
27    (@impl $scope:ident$(<$T:ident>)?) => {
28        impl$(<$T>)? Toggle for $scope$(<$T> where $T: 'static)? {}
29    };
30}
31
32impl_toggle!(
33    bool,
34    char,
35    i8,
36    i16,
37    i32,
38    i64,
39    i128,
40    isize,
41    u8,
42    u16,
43    u32,
44    u64,
45    u128,
46    usize,
47    Option<T>
48);