Skip to main content

reify_const

Function reify_const 

Source
pub fn reify_const<F, R>(val: u64, f: F) -> R
where F: FnOnce(&dyn HasModulus) -> R,
Expand description

Dispatch a runtime u64 value to the corresponding Modular<N> monomorphization, passing it to f as a &dyn HasModulus.

Supports values in 0..=255.

§Panics

Panics if val > 255 with a message indicating the value is out of the supported range.

§Examples

use const_reify::{reify_const, HasModulus};

let result = reify_const(17, |m| m.modulus());
assert_eq!(result, 17);

// Use it for computation that depends on the const value
let doubled = reify_const(21, |m| m.modulus() * 2);
assert_eq!(doubled, 42);