Macro to answer the question: does it implement a trait?
This solution has a limmitation:
Fn
/FnMut
/FnOnce
which current entity does not implement you will get compile-time error instead of false
.rust
dbg!( instance_of!( 13_i32 => Copy ) );
// < instance_of!( 13_i32 => Copy ) : true
dbg!( instance_of!( Box::new( 13_i32 ) => Copy ) );
// < instance_of!( 13_i32 => Copy ) : false
git clone https://github.com/Wandalen/wTools
cd wTools
cd sample/rust/meta_instance_of_trivial
cargo run
cargo add instance_of