2021-04-11 20:13:07 +00:00
|
|
|
//! This module is internal to crevice but used by its derive macro. No
|
|
|
|
//! guarantees are made about its contents.
|
|
|
|
|
|
|
|
pub use bytemuck;
|
|
|
|
|
2021-11-12 01:39:25 +00:00
|
|
|
/// Gives the number of bytes needed to make `offset` be aligned to `alignment`.
|
2021-04-11 20:13:07 +00:00
|
|
|
pub const fn align_offset(offset: usize, alignment: usize) -> usize {
|
2021-11-12 01:39:25 +00:00
|
|
|
if alignment == 0 || offset % alignment == 0 {
|
2021-04-11 20:13:07 +00:00
|
|
|
0
|
|
|
|
} else {
|
|
|
|
alignment - offset % alignment
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Max of two `usize`. Implemented because the `max` method from `Ord` cannot
|
|
|
|
/// be used in const fns.
|
|
|
|
pub const fn max(a: usize, b: usize) -> usize {
|
|
|
|
if a > b {
|
|
|
|
a
|
|
|
|
} else {
|
|
|
|
b
|
|
|
|
}
|
|
|
|
}
|
2021-11-12 01:39:25 +00:00
|
|
|
|
|
|
|
/// Max of an array of `usize`. This function's implementation is funky because
|
|
|
|
/// we have no for loops!
|
|
|
|
pub const fn max_arr<const N: usize>(input: [usize; N]) -> usize {
|
|
|
|
let mut max = 0;
|
|
|
|
let mut i = 0;
|
|
|
|
|
|
|
|
while i < N {
|
|
|
|
if input[i] > max {
|
|
|
|
max = input[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
i += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
max
|
|
|
|
}
|