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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use crate::Aligned;

/// [`isize`] that shifts left by `N` bits.
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Default, Hash)]
pub struct ShiftIsize<const N: isize>(isize);

impl<const N: isize> ShiftIsize<N> {
    /// Creates a new value from an unshifted number.
    #[inline]
    pub fn new(val: isize) -> Self {
        Self(val << N)
    }

    /// Returns the unshifted number.
    #[inline]
    pub fn get(&self) -> isize {
        self.0 >> N
    }

    /// Sets the value by an unshifted number.
    #[inline]
    pub fn set(&mut self, val: isize) {
        self.0 = val << N;
    }
}

unsafe impl<const N: isize> Aligned for ShiftIsize<N> {
    const ALIGNMENT: usize = 1 << N;
}

/// [`usize`] that shifts left by `N` bits.
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Default, Hash)]
pub struct ShiftUsize<const N: usize>(usize);

impl<const N: usize> ShiftUsize<N> {
    /// Creates a new value from a unshifted number.
    #[inline]
    pub fn new(val: usize) -> Self {
        Self(val << N)
    }

    /// Returns the unshifted number.
    #[inline]
    pub fn get(&self) -> usize {
        self.0 >> N
    }

    /// Sets the value by an unshifted number.
    #[inline]
    pub fn set(&mut self, val: usize) {
        self.0 = val << N;
    }
}

unsafe impl<const N: usize> Aligned for ShiftUsize<N> {
    const ALIGNMENT: usize = 1 << N;
}