[−][src]Macro assert_bound::assert_bound
Assert that expression implements trait(s) at compile-time.
Examples
use assert_bound::assert_bound; use std::fmt::Debug; assert_bound!(() => Debug + Ord + PartialEq<()>);
trait T {} impl T for () {} assert_bound!(() => T);
Note: expression is not executed:
let mut var = 0; assert_bound!({ var = 1; } => Eq); assert_eq!(var, 0);
However you can execute it by calling result of the macro:
let mut var = 0; assert_bound!({ var = 1; } => Eq)(); assert_eq!(var, 1);
ⓘThis example deliberately fails to compile
// f32/f64 doesn't implement `Eq`, // so rustc will fail to compile that. assert_bound!(0.1; Eq);
Expand
Following code:
assert_bound!({ println!("Hewwo?") } => Ord + PartialEq<()>);
expands to something like this:
|| { fn assert_bound<T>(_: &T) where T: Ord, T: PartialEq<()>, {} let expr = { println!("Hewwo?") }; assert_bound(&expr); expr };