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
27
28
29
30
31
32
33
#![no_std]

#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
pub struct Id(::core::any::TypeId);

#[macro_export]
macro_rules! id {
    () => {{
        struct Nonsense;
        $crate::Id(::core::any::TypeId::of::<Nonsense>())
    }}
}

#[cfg(test)]
mod tests {
    #[test]
    fn basic() {
        let a = id!();
        let b = id!();
        assert!(a == a);
        assert!(b == b);
        assert!(a != b);
    }

    #[test]
    fn duplicate() {
        struct Nonsense;
        let _ = Nonsense;
        let a = id!();
        let b = id!();
        assert!(a != b);
    }
}