use std::panic::AssertUnwindSafe;
pub fn catch_abort<TFunction, TReturn>(function: TFunction) -> TReturn
where
TFunction: FnOnce() -> TReturn,
{
std::panic::catch_unwind(AssertUnwindSafe(function)).unwrap_or_else(|_| std::process::abort())
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
#[repr(transparent)]
pub struct Bunch<T> {
pub source: *const T,
}
impl<T> Bunch<T> {
pub unsafe fn get(&self, index: usize) -> &T {
&*self.source.add(index)
}
pub unsafe fn slice(&self, count: usize) -> &[T] {
std::slice::from_raw_parts(self.source, count)
}
pub unsafe fn iter(&self, count: usize) -> impl Iterator<Item = &T> {
self.slice(count).into_iter()
}
}