macro_bits/
lib.rs

1#![no_std]
2
3#[macro_use]
4mod bitfield;
5#[macro_use]
6mod bit;
7#[macro_use]
8mod serializable_enum;
9#[macro_use]
10mod incomplete_const_array;
11/// Utility macros for shortend syntaxes for definitions.
12mod gen_def;
13
14pub use defile;
15
16#[macro_export]
17macro_rules! generate_conversions {
18    (u8, $representation:ty, $target_type:ty) => {
19        ::macro_bits::generate_conversions!(u8, $representation, $target_type, 0);
20        ::macro_bits::generate_conversions!(u16, $representation, $target_type);
21    };
22    (u16, $representation:ty, $target_type:ty) => {
23        ::macro_bits::generate_conversions!(u16, $representation, $target_type, 0);
24        ::macro_bits::generate_conversions!(u32, $representation, $target_type);
25    };
26    (u32, $representation:ty, $target_type:ty) => {
27        ::macro_bits::generate_conversions!(u32, $representation, $target_type, 0);
28        ::macro_bits::generate_conversions!(u64, $representation, $target_type);
29    };
30    (u64, $representation:ty, $target_type:ty) => {
31        ::macro_bits::generate_conversions!(u64, $representation, $target_type, 0);
32        ::macro_bits::generate_conversions!(u128, $representation, $target_type, 0);
33    };
34    ($to:ty, $representation:ty, $target_type:ty, $_:expr) => {
35        impl From<$to> for $target_type {
36            fn from(value: $to) -> Self {
37                Self::from_bits(value as $representation)
38            }
39        }
40        impl From<$target_type> for $to {
41            fn from(value: $target_type) -> Self {
42                value.into_bits() as $to
43            }
44        }
45    };
46}