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
use errors::{Result};
use digit;
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct BitPos(usize);
pub type DigitPos = usize;
impl BitPos {
#[inline]
pub fn to_usize(self) -> usize {
self.0
}
#[inline]
pub fn new(pos: usize) -> Result<BitPos> {
Ok(BitPos(pos))
}
#[inline]
pub(crate) fn to_pos_within_digit(self) -> BitPos {
BitPos(self.0 % digit::BITS)
}
#[inline]
pub(crate) fn to_digit_and_bit_pos(self) -> (DigitPos, BitPos) {
let digit_pos = DigitPos::from(self.0 / digit::BITS);
let bit_pos = BitPos::from(self.0 % digit::BITS);
(digit_pos, bit_pos)
}
}
impl From<usize> for BitPos {
#[inline]
fn from(pos: usize) -> BitPos {
BitPos(pos)
}
}