macro_rules! def_nat_callback {
($name:ident -> $ret:ty $body:block) => { ... };
($name:ident { $($field:ident : $fty:ty),* $(,)? } -> $ret:ty { |$s:ident| $($body:tt)* }) => { ... };
}Expand description
Define a NatCallback struct with minimal boilerplate.
Two forms:
Stateless: no captured data, just a const-generic body:
use const_reify::{def_nat_callback, nat_reify::reify_nat};
def_nat_callback!(Square -> u64 { N * N });
assert_eq!(reify_nat(5, &Square), 25);With fields: captures runtime data alongside the const generic:
use const_reify::{def_nat_callback, nat_reify::reify_nat};
def_nat_callback!(ModMul { a: u64, b: u64 } -> u64 {
|s| if N == 0 { 0 } else { (s.a % N) * (s.b % N) % N }
});
assert_eq!(reify_nat(7, &ModMul { a: 10, b: 20 }), 4);In both forms, N refers to the const-generic u64 parameter.