fixed/
macros.rs

1// Copyright © 2018–2025 Trevor Spiteri
2
3// This library is free software: you can redistribute it and/or
4// modify it under the terms of either
5//
6//   * the Apache License, Version 2.0 or
7//   * the MIT License
8//
9// at your option.
10//
11// You should have recieved copies of the Apache License and the MIT
12// License along with the library. If not, see
13// <https://www.apache.org/licenses/LICENSE-2.0> and
14// <https://opensource.org/licenses/MIT>.
15
16macro_rules! if_signed {
17    (Signed; $($rem:tt)+) => {
18        $($rem)+
19    };
20    (Unsigned; $($rem:tt)+) => {};
21}
22
23macro_rules! if_unsigned {
24    (Signed; $($rem:tt)+) => {};
25    (Unsigned; $($rem:tt)+) => {
26        $($rem)+
27    };
28}
29
30macro_rules! if_signed_unsigned {
31    (Signed, $signed:expr, $unsigned:expr $(,)?) => {
32        $signed
33    };
34    (Unsigned, $signed:expr, $unsigned:expr $(,)?) => {
35        $unsigned
36    };
37}
38
39macro_rules! if_signed_else_empty_str {
40    (Signed; $($signed:tt)*) => {
41        concat!($($signed)*)
42    };
43    (Unsigned; $($signed:tt)*) => {
44        ""
45    };
46}
47macro_rules! if_unsigned_else_empty_str {
48    (Signed; $($unsigned:tt)*) => {
49        ""
50    };
51    (Unsigned; $($unsigned:tt)*) => {
52        concat!($($unsigned)*)
53    };
54}
55
56macro_rules! doc_comment {
57    ($comment:expr; $($tt:tt)*) => {
58        #[doc = $comment]
59        $($tt)*
60    };
61}
62
63macro_rules! comment {
64    ($($comment:expr),* $(,)?; $($tt:tt)*) => {
65        doc_comment! {
66            concat!($($comment),*);
67            $($tt)*
68        }
69    };
70}