bit_fiddler/bit_fiddle_macros/max_bits.rs
1/// For getting total bit count
2/// by type or identifier.
3///
4/// # Example
5///
6/// ```
7/// use bit_fiddler::max_bits;
8///
9/// assert_eq!(max_bits!(type = i32), 32);
10/// assert_eq!(max_bits!((5 as u64)), 64);
11///
12/// let bitmap: u8 = 0;
13///
14/// assert_eq!(max_bits!(bitmap), 8);
15/// ```
16#[macro_export]
17macro_rules! max_bits {
18 ($bitmap: tt) => {
19 std::mem::size_of_val(&$bitmap) * 8
20 };
21 (type = $ty: ty) => {
22 std::mem::size_of::<$ty>() * 8
23 };
24}