arithmetic_coding_core/
bitstore.rs1use std::ops::{Add, AddAssign, Div, Mul, Shl, ShlAssign, Sub};
2
3pub trait BitStore:
6 Shl<u32, Output = Self>
7 + ShlAssign<u32>
8 + Sub<Output = Self>
9 + Add<Output = Self>
10 + Mul<Output = Self>
11 + Div<Output = Self>
12 + AddAssign
13 + PartialOrd
14 + Copy
15 + std::fmt::Debug
16{
17 const BITS: u32;
19
20 const ZERO: Self;
22
23 const ONE: Self;
25
26 fn log2(self) -> u32;
28}
29
30macro_rules! impl_bitstore {
31 ($t:ty) => {
32 impl BitStore for $t {
33 const BITS: u32 = Self::BITS;
34 const ONE: Self = 1;
35 const ZERO: Self = 0;
36
37 fn log2(self) -> u32 {
38 Self::ilog2(self)
39 }
40 }
41 };
42}
43
44impl_bitstore! {u32}
45impl_bitstore! {u64}
46impl_bitstore! {u128}
47impl_bitstore! {usize}