use core::slice::SliceIndex; pub trait GetSaferUnchecked { unsafe fn get_kinda_unchecked(&self, index: I) -> &>::Output where I: SliceIndex<[T]>; } impl GetSaferUnchecked for [T] { #[inline(always)] unsafe fn get_kinda_unchecked(&self, index: I) -> &>::Output where I: SliceIndex<[T]>, { if cfg!(debug_assertions) { &self[index] } else { self.get_unchecked(index) } } } #[inline(always)] pub unsafe fn unreachable_kinda_unchecked() -> ! { if cfg!(debug_assertions) { panic!("UB: Unreachable unchecked was executed") } else { core::hint::unreachable_unchecked() } }