use crate::Error;
#[inline]
pub(crate) fn ensure_compatible_types<T, E>() -> Result<(), Error> {
if size_of::<T>() != size_of::<E>() {
Err(Error::IncompatibleSize)
} else {
Ok(())
}
}
pub(crate) fn check_null_bytes(data: &[u8]) -> Result<bool, Error> {
if let [rest @ .., last] = data {
if rest.contains(&0) {
Err(Error::InteriorZeroElements)
} else {
Ok(*last == 0)
}
} else {
Ok(false)
}
}
pub(crate) fn copy_and_push<T: Copy>(data: &[T], to_push: T) -> alloc::vec::Vec<T> {
let mut copy = alloc::vec::Vec::new();
copy.reserve_exact(data.len() + 1);
copy.extend_from_slice(data);
copy.push(to_push);
copy
}