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
34
35
36
37
38
39
pub trait Cast<T> {
    fn cast(self) -> T;
}

impl Cast<u64> for u64 {
    fn cast(self) -> u64 {
        self
    }
}

// pointer

impl<T> Cast<*const T> for u64 {
    fn cast(self) -> *const T {
        self as *const T
    }
}

impl<T> Cast<u64> for *const T {
    fn cast(self) -> u64 {
        self as u64
    }
}

// bool

impl Cast<u64> for bool {
    #[inline(always)]
    fn cast(self) -> u64 {
        self as u64
    }
}

impl Cast<bool> for u64 {
    #[inline(always)]
    fn cast(self) -> bool {
        self != 0
    }
}