Macro const_eval_select

macro const_eval_select {
    (
        @capture$([$($binders:tt)*])? { $($arg:ident : $ty:ty = $val:expr),* $(,)? } $( -> $ret:ty )? :
        if const
            $(#[$compiletime_attr:meta])* $compiletime:block
        else
            $(#[$runtime_attr:meta])* $runtime:block
    ) => { ... },
    (
        @capture$([$($binders:tt)*])? { $($arg:ident : $ty:ty),* $(,)? } $( -> $ret:ty )? :
        if const
            $(#[$compiletime_attr:meta])* $compiletime:block
        else
            $(#[$runtime_attr:meta])* $runtime:block
    ) => { ... },
}

A macro to make it easier to invoke const_eval_select. Use as follows:

const_eval_select!(
    @capture { arg1: i32 = some_expr, arg2: T = other_expr } -> U:
    if const #[attributes_for_const_arm] {
        // Compile-time code goes here.
    } else #[attributes_for_runtime_arm] {
        // Run-time code goes here.
    }
)

The @capture block declares which surrounding variables / expressions can be used inside the if const. Note that the two arms of this if really each become their own function, which is why the macro supports setting attributes for those functions. Both functions are marked as #[inline].

See [const_eval_select()] for the rules and requirements around that intrinsic.