nanvm_lib/common/
cast.rs

1pub trait Cast<T> {
2    fn cast(self) -> T;
3}
4
5impl Cast<u64> for u64 {
6    fn cast(self) -> u64 {
7        self
8    }
9}
10
11// pointer
12
13impl<T> Cast<*const T> for u64 {
14    fn cast(self) -> *const T {
15        self as *const T
16    }
17}
18
19impl<T> Cast<u64> for *const T {
20    fn cast(self) -> u64 {
21        self as u64
22    }
23}
24
25// bool
26
27impl Cast<u64> for bool {
28    #[inline(always)]
29    fn cast(self) -> u64 {
30        self as u64
31    }
32}
33
34impl Cast<bool> for u64 {
35    #[inline(always)]
36    fn cast(self) -> bool {
37        self != 0
38    }
39}