1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//! A collection of stuff that is missing from stable std.
//! Most of this is from nightly.

pub(crate) mod iter;
pub(crate) mod nonnull;
pub(crate) mod nonzero;
pub(crate) mod pointer;
pub(crate) mod slice;
pub(crate) mod usize;

#[cfg(test)]
pub(crate) mod layout;

#[allow(dead_code)]
mod other {
    #[inline(always)]
    pub(crate) const fn const_unwrap<T: Copy>(option: Option<T>) -> T {
        match option {
            Some(value) => value,
            None => panic!("expected Some"),
        }
    }

    #[cold]
    #[inline(always)]
    pub(crate) fn cold() {}

    #[inline(always)]
    pub(crate) fn likely(condition: bool) -> bool {
        if condition {
            // ...
        } else {
            cold();
        }

        condition
    }

    #[inline(always)]
    pub(crate) fn unlikely(condition: bool) -> bool {
        if condition {
            cold();
        } else {
            // ...
        }

        condition
    }
}

pub(crate) use other::*;

macro_rules! cfg_const {
    (
        #[cfg_const($($tt:tt)*)]
        $(#[$attr:meta])*
        $vis:vis fn $ident:ident($($params:tt)*) $(-> $result:ty)? $body:block
    ) => {
        #[cfg($($tt)*)]
        $(#[$attr])*
        $vis const fn $ident($($params)*) $(-> $result)? $body

        #[cfg(not($($tt)*))]
        $(#[$attr])*
        $vis fn $ident($($params)*) $(-> $result)? $body
    };
}

pub(crate) use cfg_const;