diagnostics_tools/diag/rta.rs
1/// Define a private namespace for all its items.
2mod private
3{
4
5 ///
6 /// Asserts that a boolean expression is true at runtime.
7 ///
8 /// This will invoke the panic! macro if the provided expression cannot be evaluated to true at runtime.
9 ///
10 /// ### Basic use-case.
11 ///
12 /// ``` rust
13 /// use diagnostics_tools::prelude::*;
14 /// a_true!( 1 == 1, "something wrong" );
15 /// ```
16 ///
17
18 #[ macro_export ]
19 macro_rules! a_true
20 {
21 () => {};
22 (
23 $( $Rest : tt )*
24 )
25 =>
26 {
27 assert!( $( $Rest )* );
28 };
29 }
30
31 ///
32 /// Asserts that a boolean expression is false at runtime.
33 ///
34 /// This will invoke the panic! macro if the provided expression cannot be evaluated to false at runtime.
35 ///
36 /// ### Basic use-case.
37 ///
38 /// ``` should_panic
39 /// use diagnostics_tools::prelude::*;
40 /// a_true!( 1 == 2, "something wrong" );
41 /// ```
42 ///
43
44 #[ macro_export ]
45 macro_rules! a_false
46 {
47 () => {};
48 (
49 $( $Rest : tt )*
50 )
51 =>
52 {
53 assert!( ! $( $Rest )* );
54 };
55 }
56
57 ///
58 /// Asserts that a boolean expression is true at runtime.
59 ///
60 /// This will invoke the panic! macro if the provided expression cannot be evaluated to true at runtime.
61 /// Like [a_true!], this macro also has a second version, where a custom panic message can be provided.
62 ///
63 /// ### Basic use-case.
64 ///
65 /// ``` rust
66 /// use diagnostics_tools::prelude::*;
67 /// a_dbg_true!( 1 == 1, "something wrong" );
68 /// ```
69 ///
70
71 #[ macro_export ]
72 macro_rules! a_dbg_true
73 {
74 () => {};
75 (
76 $( $Rest : tt )*
77 )
78 =>
79 {
80 debug_assert!( $( $Rest )* );
81 };
82 }
83
84 ///
85 /// Asserts that a boolean expression is false at runtime.
86 ///
87 /// This will invoke the panic! macro if the provided expression cannot be evaluated to false at runtime.
88 /// Like [a_false!], this macro also has a second version, where a custom panic message can be provided.
89 ///
90 /// ### Basic use-case.
91 ///
92 /// ``` should_panic
93 /// use diagnostics_tools::prelude::*;
94 /// a_dbg_true!( 1 == 2, "something wrong" );
95 /// ```
96 ///
97
98 #[ macro_export ]
99 macro_rules! a_dbg_false
100 {
101 () => {};
102 (
103 $( $Rest : tt )*
104 )
105 =>
106 {
107 debug_assert!( ! $( $Rest )* );
108 };
109 }
110
111 ///
112 /// Asserts that two expressions are identical.
113 ///
114 /// This macro will invoke the panic! macro if the two expressions have different values at runtime.
115 /// Like [a_id!], this macro also has a second version where a custom panic message can be provided.
116 ///
117 /// ### Basic use-case.
118 ///
119 /// ``` rust
120 /// use diagnostics_tools::prelude::*;
121 /// a_dbg_id!( 1, 1, "something wrong" );
122 /// ```
123 ///
124
125 #[ macro_export ]
126 macro_rules! a_dbg_id
127 {
128 (
129 $( $arg:tt )*
130 )
131 =>
132 {
133 if cfg!( debug_assertions )
134 {
135 $crate::a_id!( $( $arg )* );
136 }
137 };
138
139 }
140
141 ///
142 /// Asserts that two expressions are not identical with each other.
143 ///
144 /// This will invoke the panic! macro if two experessions have the same value at runtime.
145 /// Like [a_id!], this macro also has a second version, where a custom panic message can be provided.
146 ///
147 /// ### Basic use-case.
148 ///
149 /// ``` rust
150 /// use diagnostics_tools::prelude::*;
151 /// a_dbg_not_id!( 1, 2, "something wrong" );
152 /// ```
153 ///
154
155 #[ macro_export ]
156 macro_rules! a_dbg_not_id
157 {
158 (
159 $( $arg:tt )*
160 )
161 =>
162 {
163 if cfg!( debug_assertions )
164 {
165 $crate::a_not_id!( $( $arg )* );
166 }
167 };
168
169 }
170
171 // xxx : qqq : improve a_id and other similar macroses, make sure message is visible int console
172 // a_id!( exp, got, "Failed: path_with_trailing_dot_or_dotdot_segments. Expected: '{}', got: '{}'", exp, got );
173
174 ///
175 /// Asserts that two expressions are identical to each other (using [`PartialEq`]). Prints nice diff.
176 ///
177
178 #[macro_export]
179 macro_rules! a_id
180 {
181 ( $left:expr , $right:expr $(,)? )
182 =>
183 ({
184 $crate::dependency::pretty_assertions::assert_eq!( $left, $right );
185 });
186 ($left:expr, $right:expr, $($arg:tt)*)
187 =>
188 ({
189 $crate::dependency::pretty_assertions::assert_eq!( $left, $right, $($arg)+ );
190 });
191 }
192
193 ///
194 /// Asserts that two expressions are not identical to each other (using [`PartialEq`]). Prints nice diff.
195 ///
196
197 #[macro_export]
198 macro_rules! a_not_id
199 {
200 ( $left:expr , $right:expr $(,)? )
201 =>
202 ({
203 $crate::dependency::pretty_assertions::assert_ne!( $left, $right );
204 });
205 ($left:expr, $right:expr, $($arg:tt)*)
206 =>
207 ({
208 $crate::dependency::pretty_assertions::assert_ne!( $left, $right, $($arg)+ );
209 });
210 }
211
212 pub use a_id;
213 pub use a_not_id;
214 pub use a_true;
215 pub use a_false;
216 pub use a_dbg_true;
217 pub use a_dbg_false;
218 pub use a_dbg_id;
219 pub use a_dbg_not_id;
220}
221
222#[ doc( inline ) ]
223#[ allow( unused_imports ) ]
224pub use own::*;
225
226/// Own namespace of the module.
227#[ allow( unused_imports ) ]
228pub mod own
229{
230 use super::*;
231 #[ doc( inline ) ]
232 pub use orphan::*;
233}
234
235/// Orphan namespace of the module.
236#[ allow( unused_imports ) ]
237pub mod orphan
238{
239 use super::*;
240
241 #[ doc( inline ) ]
242 pub use exposed::*;
243
244 #[ doc( inline ) ]
245 pub use private::a_id as assert_eq;
246 #[ doc( inline ) ]
247 pub use private::a_not_id as assert_ne;
248
249}
250
251/// Exposed namespace of the module.
252#[ allow( unused_imports ) ]
253pub mod exposed
254{
255 use super::*;
256 #[ doc( inline ) ]
257 pub use prelude::*;
258}
259
260/// Prelude to use essentials: `use my_module::prelude::*`.
261#[ allow( unused_imports ) ]
262pub mod prelude
263{
264 use super::*;
265
266 // #[ doc( inline ) ]
267 // #[ allow( unused_imports ) ]
268 // pub use ::pretty_assertions::assert_eq as a_id;
269 // #[ doc( inline ) ]
270 // #[ allow( unused_imports ) ]
271 // pub use ::pretty_assertions::assert_ne as a_not_id;
272
273 #[ doc( inline ) ]
274 #[ allow( unused_imports ) ]
275 pub use private::a_id;
276 #[ doc( inline ) ]
277 #[ allow( unused_imports ) ]
278 pub use private::a_not_id;
279
280 #[ doc( inline ) ]
281 pub use private::
282 {
283 a_true,
284 a_false,
285 a_dbg_true,
286 a_dbg_false,
287 a_dbg_id,
288 a_dbg_not_id,
289 };
290
291}