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
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144

/// Panics if the first expression is not strictly greater_or_equal than the second.
///
/// Requires that the values implement `PartialOrd` and `Debug`.
///
/// Note: is also aliased as `chek::ge!`. A debug-only version is available as
/// `chek::debug_greater_or_equal!`.
///
/// On failure, panics and prints the values out in a manner similar to
/// prelude's `assert_eq!`.
///
/// Optionally may take an additional message to display on failure, which is
/// formatted using standard format syntax.
///
/// # Example
///
/// ```rust
/// chek::greater_or_equal!(4, 3);
/// chek::greater_or_equal!(4, 4);
/// chek::greater_or_equal!(4, 3, "With a message");
/// chek::greater_or_equal!(4, 3, "With a formatted message: {}", "oh no");
/// ```
#[macro_export]
macro_rules! greater_or_equal {
    ($left:expr, $right:expr $(,)?) => ({
        let (left, right) = (&($left), &($right));
        if !(left >= right) {
            $crate::__cmp_assert_fail!("greater_or_equal", left, right, stringify!($left), stringify!($right));
        }
    });
    ($left:expr, $right:expr, $($msg_args:tt)+) => ({
        let (left, right) = (&($left), &($right));
        if !(left >= right) {
            $crate::__cmp_assert_fail!("greater_or_equal", left, right, stringify!($left), stringify!($right), format_args!($($msg_args)+))
        }
    })
}

/// Panics if the first expression is not strictly greater_or_equal than the second.
///
/// Requires that the values implement `PartialOrd` and `Debug`.
///
/// Note: is also aliased as `chek::greater_or_equal!`. A debug-only version is available as
/// `chek::debug_ge!`.
///
/// Optionally may take an additional message to display on failure, which is
/// formatted using standard format syntax.
///
/// # Example
///
/// ```rust
/// chek::ge!(4, 3);
/// chek::ge!(4, 4);
/// chek::ge!(4, 3, "With a message");
/// chek::ge!(4, 3, "With a formatted message: {}", "oh no");
/// ```
#[macro_export]
macro_rules! ge {
    ($left:expr, $right:expr $(,)?) => ({
        let (left, right) = (&($left), &($right));
        if !(left >= right) {
            $crate::__cmp_assert_fail!("ge", left, right, stringify!($left), stringify!($right));
        }
    });
    ($left:expr, $right:expr, $($msg_args:tt)+) => ({
        let (left, right) = (&($left), &($right));
        if !(left >= right) {
            $crate::__cmp_assert_fail!("ge", left, right, stringify!($left), stringify!($right), format_args!($($msg_args)+))
        }
    })
}

/// Same as `chek::greater_or_equal!` in debug builds or release builds where the `-C
/// debug-assertions` was provided to the compiler. For all other builds,
/// vanishes without a trace.
///
/// Optionally may take an additional message to display on failure, which is
/// formatted using standard format syntax.
///
/// # Example
///
/// ```rust
/// // These are compiled to nothing if debug_assertions are off!
/// chek::debug_greater_or_equal!(4, 3);
/// chek::debug_greater_or_equal!(4, 4);
/// chek::debug_greater_or_equal!(4, 3, "With a message");
/// chek::debug_greater_or_equal!(4, 3, "With a formatted message: {}", "oh no");
/// ```
#[macro_export]
macro_rules! debug_greater_or_equal {
    ($left:expr, $right:expr $(,)?) => ({
        if cfg!(debug_assertions) {
            let (left, right) = (&($left), &($right));
            if !(left >= right) {
                $crate::__cmp_assert_fail!("debug_greater_or_equal", left, right, stringify!($left), stringify!($right));
            }
        }
    });
    ($left:expr, $right:expr, $($msg_args:tt)+) => ({
        if cfg!(debug_assertions) {
            let (left, right) = (&($left), &($right));
            if !(left >= right) {
                $crate::__cmp_assert_fail!("debug_greater_or_equal", left, right, stringify!($left), stringify!($right), format_args!($($msg_args)+))
            }
        }
    })
}

/// Same as `chek::ge!` in debug builds or release builds where the `-C
/// debug-assertions` was provided to the compiler. For all other builds,
/// vanishes without a trace.
///
/// Optionally may take an additional message to display on failure, which is
/// formatted using standard format syntax.
///
/// # Example
///
/// ```rust
/// // These are compiled to nothing if debug_assertions are off!
/// chek::debug_ge!(4, 3);
/// chek::debug_ge!(4, 4);
/// chek::debug_ge!(4, 3, "With a message");
/// chek::debug_ge!(4, 3, "With a formatted message: {}", "oh no");
/// ```
#[macro_export]
macro_rules! debug_ge {
    ($left:expr, $right:expr $(,)?) => ({
        if cfg!(debug_assertions) {
            let (left, right) = (&($left), &($right));
            if !(left >= right) {
                $crate::__cmp_assert_fail!("debug_ge", left, right, stringify!($left), stringify!($right));
            }
        }
    });
    ($left:expr, $right:expr, $($msg_args:tt)+) => ({
        if cfg!(debug_assertions) {
            let (left, right) = (&($left), &($right));
            if !(left >= right) {
                $crate::__cmp_assert_fail!("debug_ge", left, right, stringify!($left), stringify!($right), format_args!($($msg_args)+))
            }
        }
    })
}