Skip to main content

const_assert

Macro const_assert 

Source
macro_rules! const_assert {
    (   /* logical comparisons */

        // Asserts that a single expression evaluates to `true`.
        $x:expr $(,)?) => { ... };
    (
        // Asserts that constants are equal in value.
        eq $x:expr, $($y:expr),+ $(,)?) => { ... };
    (
        // Asserts that constants of type `usize` are equal in value.
        //
        // Allows inspecting the values of the constants in error messages. E.g.:
        // "expected an array with a size of 3, found one with a size of 4"
        eq_usize $x:expr, $($y:expr),+ $(,)?) => { ... };
    (
        // Asserts that constants are NOT equal in value.
        ne $x:expr, $($y:expr),+ $(,)?) => { ... };
    (
        // Asserts that constants are less than each other.
        lt $x:expr, $($y:expr),+ $(,)?) => { ... };
    (
        // Asserts that constants are less than or equal to each other.
        le $x:expr, $($y:expr),+ $(,)?) => { ... };
    (
        // Asserts that constants are greater than each other.
        gt $x:expr, $($y:expr),+ $(,)?) => { ... };
    (
        // Asserts that constants are greater than or equal to each other.
        ge $x:expr, $($y:expr),+ $(,)?) => { ... };
    (
        /* comparisons of slices of primitives (as well as slices of slices)
         * supports all integer primitives, bool, char and &str. */

        // Asserts that slice buffers of $p primitives are equal in value.
        eq_buf::<$p:ty> $buf:expr, $($other:expr),+ $(,)?) => { ... };
    (   // (defaults to bytes)
        eq_buf $buf:expr, $($other:expr),+ $(,)?) => { ... };
    (
        // Asserts that slice buffers of $p primitives are NOT equal in value.
        ne_buf::<$p:ty> $buf:expr, $($other:expr),+ $(,)?) => { ... };
    (   // (defaults to bytes)
        ne_buf $buf:expr, $($other:expr),+ $(,)?) => { ... };
    (
        /* comparisons of string slices (for convenience) */

        // Asserts that string slices are equal in value.
        eq_str $str:expr, $($other:expr),+ $(,)?) => { ... };
    (
        // Asserts that string slices are NOT equal in value.
        ne_str $str:expr, $($other:expr),+ $(,)?) => { ... };
    (   /* private arms*/
     @build $x:expr, $($y:expr),+; $op:tt) => { ... };
    (@build $x:expr; $op:tt) => { ... };
}
Expand description

💯 Asserts various comparisons on constants.

📍 code/util/assert::const_assert!