#traits #wtools #general-purpose

no-std dev implements

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

21 releases (12 breaking)

new 0.12.0 Apr 13, 2025
0.10.0 Oct 30, 2024
0.8.0 May 11, 2024
0.7.0 Mar 16, 2024
0.0.6 Nov 29, 2021

#8 in #wtools

Download history 45/week @ 2024-12-22 20/week @ 2024-12-29 71/week @ 2025-01-05 52/week @ 2025-01-12 78/week @ 2025-01-19 45/week @ 2025-01-26 80/week @ 2025-02-02 82/week @ 2025-02-09 221/week @ 2025-02-16 213/week @ 2025-02-23 76/week @ 2025-03-02 107/week @ 2025-03-09 169/week @ 2025-03-16 46/week @ 2025-03-23 151/week @ 2025-03-30 179/week @ 2025-04-06

557 downloads per month
Used in 75 crates (3 directly)

MIT license

9KB
99 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

Features