use ::core::{
mem,
ops::{Bound, Range, RangeBounds},
};
pub(crate) trait TypeMeta {
const IS_ZST: bool;
}
impl<T> TypeMeta for T {
const IS_ZST: bool = mem::size_of::<T>() == 0;
}
#[inline]
pub(crate) fn conform_range(
range: impl RangeBounds<usize>,
max: usize,
) -> Range<usize> {
let end = match range.end_bound() {
Bound::Excluded(&b) if b <= max => Some(b),
Bound::Included(&b) if b < max => Some(b + 1),
Bound::Unbounded => Some(max),
_ => None,
};
let start = match range.start_bound() {
Bound::Included(&b) if Some(b) <= end => Some(b),
Bound::Excluded(&b) if Some(b) < end => Some(b + 1),
Bound::Unbounded => Some(0),
_ => None,
};
let (Some(start), Some(end)) = (start, end) else {
panic!("invalid range")
};
start..end
}