slotmap/
util.rs

1use core::fmt::Debug;
2
3/// Internal stable replacement for !.
4#[derive(Debug)]
5pub enum Never {}
6
7pub trait UnwrapNever<T> {
8    fn unwrap_never(self) -> T;
9}
10
11impl<T> UnwrapNever<T> for Result<T, Never> {
12    #[inline(always)]
13    fn unwrap_never(self) -> T {
14        match self {
15            Ok(x) => x,
16            Err(e) => match e {},
17        }
18    }
19}
20
21/// Returns if a is an older version than b, taking into account wrapping of
22/// versions.
23pub fn is_older_version(a: u32, b: u32) -> bool {
24    let diff = a.wrapping_sub(b);
25    diff >= (1 << 31)
26}
27
28pub struct PanicOnDrop(pub &'static str);
29impl Drop for PanicOnDrop {
30    fn drop(&mut self) {
31        panic!("{}", self.0);
32    }
33}