#fundamental #general-purpose

instance_of

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

5 releases

0.1.0 Jan 10, 2022
0.0.8 Dec 7, 2021
0.0.7 Nov 29, 2021
0.0.6 Nov 29, 2021
0.0.4 Nov 29, 2021

#645 in Algorithms

Download history 2/week @ 2022-11-28 3/week @ 2022-12-05 4/week @ 2022-12-12 470/week @ 2022-12-19 322/week @ 2022-12-26 2/week @ 2023-01-02 157/week @ 2023-01-09 652/week @ 2023-01-16 364/week @ 2023-01-23 372/week @ 2023-01-30 546/week @ 2023-02-06 97/week @ 2023-02-13 905/week @ 2023-02-20 267/week @ 2023-02-27 122/week @ 2023-03-06 1088/week @ 2023-03-13

2,393 downloads per month

MIT license

9KB
82 lines

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

lib.rs:

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.

Dependencies