#[macro_export]
macro_rules! static_assert {
($($tt:tt)*) => {
#[allow(dead_code, clippy::assertions_on_constants)]
const _: () = assert!($($tt)*);
}
}
pub use crate::static_assert;
#[track_caller]
pub unsafe fn slice_to_array<T, const N: usize>(
slice: &[T],
) -> &[T; N] {
assert!(slice.len() >= N, "slice is smaller than N");
slice
.as_ptr()
.cast::<[T; N]>()
.as_ref()
.expect("failed to cast N-sized slice to N-sized array")
}
#[track_caller]
pub unsafe fn slice_to_array_mut<T, const N: usize>(
slice: &mut [T],
) -> &mut [T; N] {
assert!(slice.len() >= N, "slice is smaller than N");
slice
.as_mut_ptr()
.cast::<[T; N]>()
.as_mut()
.expect("failed to cast N-sized slice to N-sized array")
}