spacetimedb_table/util.rs
1use core::ops::Range;
2
3/// Translates the range `r` by adding `by` to both its `start` and its `end`.
4///
5/// The resulting range will have the same length as `r`.
6pub const fn range_move(r: Range<usize>, by: usize) -> Range<usize> {
7 (r.start + by)..(r.end + by)
8}
9
10/// Asserts that `$ty` is `$size` bytes in `static_assert_size($ty, $size)`.
11///
12/// Example:
13///
14/// ```ignore
15/// static_assert_size!(u32, 4);
16/// ```
17#[macro_export]
18macro_rules! static_assert_size {
19 ($ty:ty, $size:expr) => {
20 const _: [(); $size] = [(); ::core::mem::size_of::<$ty>()];
21 };
22}
23
24/// Asserts that `$ty` is aligned at `$align` bytes in `static_assert_align($ty, $align)`.
25///
26/// Example:
27///
28/// ```ignore
29/// static_assert_align!(u32, 2);
30/// ```
31#[macro_export]
32macro_rules! static_assert_align {
33 ($ty:ty, $align:expr) => {
34 const _: [(); $align] = [(); ::core::mem::align_of::<$ty>()];
35 };
36}