#traits #fundamental #general-purpose #macro #entity #questions #compile-time

no-std dev implements

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

16 releases (7 breaking)

0.7.0 Mar 16, 2024
0.5.0 Mar 16, 2024
0.3.0 Oct 28, 2023
0.1.1 May 25, 2022
0.0.6 Nov 29, 2021

#1640 in Development tools

Download history 128/week @ 2023-12-23 28/week @ 2023-12-30 143/week @ 2024-01-06 216/week @ 2024-01-13 91/week @ 2024-01-20 61/week @ 2024-01-27 72/week @ 2024-02-03 142/week @ 2024-02-10 172/week @ 2024-02-17 232/week @ 2024-02-24 196/week @ 2024-03-02 192/week @ 2024-03-09 646/week @ 2024-03-16 238/week @ 2024-03-23 256/week @ 2024-03-30 113/week @ 2024-04-06

1,261 downloads per month
Used in 81 crates (2 directly)

MIT license

10KB
95 lines

Module :: implements

experimental rust-status docs.rs Open in Gitpod discord

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

This solution has a limitation:

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

Basic use-case

use implements::*;

dbg!( implements!( 13_i32 => Copy ) );
// < implements!( 13_i32 => Copy ) : true
dbg!( implements!( Box::new( 13_i32 ) => Copy ) );
// < implements!( 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
cargo run --example implements_trivial

No runtime deps