instance_of

Crates.ioinstance_of
lib.rsinstance_of
version0.1.0
sourcesrc
created_at2021-11-29 14:12:24.258207
updated_at2022-01-10 14:46:40.781322
descriptionMacro to answer the question: does it implement a trait?
homepagehttps://github.com/Wandalen/wTools/tree/master/module/rust/instance_of
repositoryhttps://github.com/Wandalen/wTools/tree/master/module/rust/instance_of
max_upload_size
id489262
size5,973
Wandalen (Wandalen)

documentation

https://docs.rs/instance_of

README

module::instance_of

Macro to answer the question: does it implement a trait?

This solution has a limitation:

  • In case enity is a function and trat is Fn/FnMut/FnOnce which current entity does not implement you will get compile-time error instead of false.

This is alias for module::implements.

Sample

use instance_of::*;

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

To add to your project

cargo add implements

Try out from the repository

git clone https://github.com/Wandalen/wTools
cd wTools
cd sample/rust/implements_trivial
cargo run
Commit count: 0

cargo fmt