#[macro_export]
macro_rules! match_each_power_of_two_width {
(
$byte_width:expr,
widths = [$($width:literal),+ $(,)?],
|$W:ident| $body:block,
$other:pat => $fallback:block $(,)?
) => {{
let byte_width: usize = $byte_width;
match byte_width {
$(
$width => {
const $W: usize = $width;
const { assert!($W.is_power_of_two(), "width must be a nonzero power of two") };
$body
},
)+
$other => $fallback,
}
}};
(
$byte_width:expr,
|$W:ident| $body:block,
$other:pat => $fallback:block $(,)?
) => {
$crate::match_each_power_of_two_width!(
$byte_width,
widths = [1, 2, 4, 8, 16, 32],
|$W| $body,
$other => $fallback,
)
};
}
#[macro_export]
macro_rules! buffer {
() => (
$crate::Buffer::empty()
);
($start:tt .. $end:tt) => (
$crate::Buffer::from_iter($start..$end)
);
($start:tt ..= $end:tt) => (
$crate::Buffer::from_iter($start..=$end)
);
($elem:expr; $n:expr) => (
$crate::Buffer::full($elem, $n)
);
($($x:expr),+ $(,)?) => (
$crate::Buffer::from_iter([$($x),+])
);
}
#[macro_export]
macro_rules! buffer_mut {
() => (
$crate::BufferMut::empty()
);
($start:tt .. $end:tt) => (
$crate::BufferMut::from_iter($start..$end)
);
($start:tt ..= $end:tt) => (
$crate::BufferMut::from_iter($start..=$end)
);
($elem:expr; $n:expr) => (
$crate::BufferMut::full($elem, $n)
);
($($x:expr),+ $(,)?) => (
$crate::BufferMut::from_iter([$($x),+])
);
}