implements/
lib.rs

1#![ cfg_attr( feature = "no_std", no_std ) ]
2#![ doc( html_logo_url = "https://raw.githubusercontent.com/Wandalen/wTools/master/asset/img/logo_v3_trans_square.png" ) ]
3#![ doc( html_favicon_url = "https://raw.githubusercontent.com/Wandalen/wTools/alpha/asset/img/logo_v3_trans_square_icon_small_v2.ico" ) ]
4#![ doc( html_root_url = "https://docs.rs/implements/latest/implements/" ) ]
5// #![ deny( rust_2018_idioms ) ]
6// #![ deny( missing_debug_implementations ) ]
7// #![ deny( missing_docs ) ]
8
9//!
10//! Macro to answer the question: does it implement a trait?
11//!
12
13#![ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "Readme.md" ) ) ]
14
15// #[ macro_use ]
16#[ cfg( feature = "enabled" ) ]
17mod implements_impl;
18
19/// Define a private namespace for all its items.
20#[ cfg( feature = "enabled" ) ]
21mod private
22{
23  /// Macro `implements` to answer the question: does it implement a trait?
24  ///
25  /// ### Basic use-case.
26  /// ```
27  /// use implements::*;
28  /// dbg!( implements!( 13_i32 => Copy ) );
29  /// // < implements!( 13_i32 => Copy ) : true
30  /// dbg!( implements!( Box::new( 13_i32 ) => Copy ) );
31  /// // < implements!( 13_i32 => Copy ) : false
32  /// ```
33  #[ macro_export ]
34  macro_rules! implements
35  {
36    ( $( $arg : tt )+ ) =>
37    {
38      $crate::_implements!( $( $arg )+ );
39    }
40  }
41
42  /// Macro `instance_of` to answer the question: does it implement a trait? Alias of the macro `implements`.
43  ///
44  /// ### Basic use-case.
45  /// ```
46  /// use implements::instance_of;
47  /// dbg!( instance_of!( 13_i32 => Copy ) );
48  /// // < instance_of!( 13_i32 => Copy ) : true
49  /// dbg!( instance_of!( Box::new( 13_i32 ) => Copy ) );
50  /// // < instance_of!( 13_i32 => Copy ) : false
51  /// ```
52  #[ macro_export ]
53  macro_rules! instance_of
54  {
55    ( $( $arg : tt )+ ) =>
56    {
57      $crate::_implements!( $( $arg )+ );
58    }
59  }
60
61  pub use implements;
62  pub use instance_of;
63}
64
65#[ doc( inline ) ]
66#[ allow( unused_imports ) ]
67#[ cfg( feature = "enabled" ) ]
68pub use own::*;
69
70/// Own namespace of the module.
71#[ cfg( feature = "enabled" ) ]
72#[ allow( unused_imports ) ]
73pub mod own
74{
75  use super::*;
76  #[ doc( inline ) ]
77  pub use orphan::*;
78}
79
80/// Orphan namespace of the module.
81#[ cfg( feature = "enabled" ) ]
82#[ allow( unused_imports ) ]
83pub mod orphan
84{
85  use super::*;
86  #[ doc( inline ) ]
87  pub use exposed::*;
88}
89
90/// Exposed namespace of the module.
91#[ cfg( feature = "enabled" ) ]
92#[ allow( unused_imports ) ]
93pub mod exposed
94{
95  use super::*;
96  #[ doc( inline ) ]
97  pub use prelude::*;
98}
99
100/// Prelude to use essentials: `use my_module::prelude::*`.
101#[ cfg( feature = "enabled" ) ]
102#[ allow( unused_imports ) ]
103pub mod prelude
104{
105  use super::{ private };
106  #[ doc( inline ) ]
107  pub use private::
108  {
109    implements,
110    instance_of,
111  };
112}