digit_layout/
macros.rs

1/// Defines an instance of [`DigitLayout`](crate::DigitLayout).
2#[macro_export]
3macro_rules! layout {
4    ($name:ident u($bits:expr); $group:expr) => {
5        // 允许使用小写常量名,因为这是用户定义的布局名称,应该保持原始大小写
6        #[allow(non_upper_case_globals)]
7        pub const $name: $crate::DigitLayout = $crate::DigitLayout::unsigned($bits, $group);
8    };
9    ($name:ident e($exponent:expr)m($mantissa:expr); $group:expr) => {
10        // 允许使用小写常量名,因为这是用户定义的布局名称,应该保持原始大小写
11        #[allow(non_upper_case_globals)]
12        pub const $name: $crate::DigitLayout = $crate::DigitLayout::real($exponent, $mantissa, $group);
13    };
14    ($name:ident = $text:expr; [$group:expr] in $size:expr) => {
15        // 允许使用小写常量名,因为这是用户定义的布局名称,应该保持原始大小写
16        #[allow(non_upper_case_globals)]
17        pub const $name: $crate::DigitLayout = $crate::DigitLayout::named($text, $group, $size);
18    };
19
20    ($name:ident u($bits:expr)) => {
21        $crate::layout!($name u($bits); 1);
22    };
23    ($name:ident i($bits:expr)) => {
24        $crate::layout!($name e(0)m($bits - 1); 1);
25    };
26    ($name:ident e($exponent:expr)m($mantissa:expr)) => {
27        $crate::layout!($name e($exponent)m($mantissa); 1);
28    };
29    ($name:ident; [$group:expr] in $size:expr) => {
30        $crate::layout!($name = stringify!($name); [$group] in $size);
31    };
32}