guard

Attribute Macro guard 

Source
#[guard]
Expand description

ยงMacro Expansion

This simple function with a const guard

fn main() {
   f::<0>()
}

#[guard(N > 0)]
fn f<const N: usize>() {
   todo!()
}

would expand to

struct Guard<const U: bool>;
trait Protect {}
impl Protect for Guard<true> {}
 
fn main() {
   f::<0>()
}

fn f<const N: usize>()
where
   Guard<{
       const fn _f_guard<const N: usize>() -> bool {
           if !N > 0 {
               panic!("guard evaluated to false")
           }
           true
       }
       _f_guard::<N>()
   }>: Protect,
{
   todo!()
}