#traits #run-time #macro #check

is_trait

Add a macro to check if a type implements a trait at runtime

5 releases

0.1.4 May 8, 2022
0.1.3 May 8, 2022
0.1.2 May 8, 2022
0.1.1 May 8, 2022
0.1.0 May 8, 2022

#2342 in Rust patterns

24 downloads per month

MIT/Apache

7KB
58 lines

docs.rs Crates.io

is_trait

This crate adds a macro is_trait::is_trait! that returns a bool of whether or not a type implements a specific trait. See crate level documentation


lib.rs:

This crate adds a is_trait! macro for getting a runtime value for if a type implements a trait This can be useful for test, where you can have a test fail instead of getting a compile error Example:

use is_trait::is_trait;
 
struct Thing;
struct OtherThing;
trait SomeTrait {}
impl SomeTrait for Thing {}
assert!(is_trait!(Thing, SomeTrait));
assert!(is_trait!(OtherThing, SomeTrait)); // FAILS

No runtime deps