1#[cfg(feature = "copy")]
2macro_rules! default {
3 (#[inline] $($fn:tt)*) => { #[inline] default $($fn)* };
4 ($($fn:tt)*) => { default $($fn)* };
5}
6
7#[cfg(not(feature = "copy"))]
8macro_rules! default {
9 (#[inline] $($fn:tt)*) => { #[inline] $($fn)* };
10 ($($fn:tt)*) => { $($fn)* };
11}
12
13#[macro_export]
39macro_rules! out_field {
40 ($out:ident.$field:tt) => {{
41 #[allow(unused_unsafe)]
42 unsafe {
43 let fo = ::core::ptr::addr_of_mut!((*$out).$field);
44 (fo.cast::<u8>().offset_from($out.cast::<u8>()) as usize, fo)
45 }
46 }};
47}
48
49#[macro_export]
58macro_rules! from_archived {
59 ($expr:expr) => {{
60 #[cfg(not(any(feature = "archive_le", feature = "archive_be")))]
61 {
62 $expr
63 }
64 #[cfg(any(feature = "archive_le", feature = "archive_be"))]
65 {
66 ($expr).value()
67 }
68 }};
69}
70
71#[cfg(any(feature = "archive_le", feature = "archive_be"))]
72pub use crate::rend::NativeEndian;
73
74#[macro_export]
83macro_rules! to_archived {
84 ($expr:expr) => {{
85 #[cfg(not(any(feature = "archive_le", feature = "archive_be")))]
86 {
87 $expr
88 }
89 #[cfg(feature = "archive_le")]
90 {
91 $crate::macros::NativeEndian { value: $expr }.to_le()
92 }
93 #[cfg(feature = "archive_be")]
94 {
95 $crate::macros::NativeEndian { value: $expr }.to_be()
96 }
97 }};
98}
99
100#[cfg(not(any(feature = "size_16", feature = "size_32", feature = "size_64")))]
101core::compile_error!(r#"one of ["size_16", "size_32", or "size_64"] features must be enabled"#);
102
103#[cfg(all(feature = "size_16", feature = "size_32"))]
104core::compile_error!(
105 "\"size_16\" and \"size_32\" are mutually-exclusive features. You may need to set \
106 `default-features = false` or compile with `--no-default-features`."
107);
108#[cfg(all(feature = "size_16", feature = "size_64"))]
109core::compile_error!(
110 "\"size_16\" and \"size_64\" are mutually-exclusive features. You may need to set \
111 `default-features = false` or compile with `--no-default-features`."
112);
113#[cfg(all(feature = "size_32", feature = "size_64"))]
114core::compile_error!(
115 "\"size_32\" and \"size_64\" are mutually-exclusive features. You may need to set \
116 `default-features = false` or compile with `--no-default-features`."
117);
118
119#[cfg(feature = "size_16")]
120macro_rules! pick_size_type {
121 ($s16:ty, $s32:ty, $s64:ty) => {
122 $s16
123 };
124 ($s16:ty, $s32:ty, $s64:ty,) => {
125 pick_size_type!($s16, $s32, $s64)
126 };
127}
128
129#[cfg(feature = "size_32")]
130macro_rules! pick_size_type {
131 ($s16:ty, $s32:ty, $s64:ty) => {
132 $s32
133 };
134 ($s16:ty, $s32:ty, $s64:ty,) => {
135 pick_size_type!($s16, $s32, $s64)
136 };
137}
138
139#[cfg(feature = "size_64")]
140macro_rules! pick_size_type {
141 ($s16:ty, $s32:ty, $s64:ty) => {
142 $s64
143 };
144 ($s16:ty, $s32:ty, $s64:ty,) => {
145 pick_size_type!($s16, $s32, $s64)
146 };
147}