1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
//! # `benri`
//! Convenient macros wrapping the standard library.
//!
//! This library provides convenient `macros` around [`std`] functionality.
//!
//! ## Modules
//! Due to how Rust macros are currently exported, all macros
//! will show up in the global namespace: `benri::*`.
//!
//! To use specific types of macros, you can import the module instead:
//! ```rust
//! use benri::time::*;
//!
//! let now = now!();
//! ```
//!
//! ## Feature flags
//! - `log` - Enable [`log`](https://docs.rs/log) usage in certain places
//!
//! ### Example 1 - Flip a bool:
//! ```rust
//! # use benri::ops::*;
//! let mut a = false;
//! flip!(a);
//! assert!(a == true);
//! flip!(a);
//! assert!(a == false);
//! ```
//!
//! ### Example 2 - Get the current `Instant`:
//! ```rust
//! # use benri::time::*;
//! let now = now!();
//!
//! std::thread::sleep(std::time::Duration::from_secs(1));
//!
//! assert!(now.elapsed().as_secs() >= 1);
//!```
//!
//! ### Example 3 - Get elapsed `Instant` time:
//! ```rust
//! # use benri::time::*;
//! let now = now!();
//!
//! std::thread::sleep(std::time::Duration::from_secs(1));
//! assert!(secs!(now) >= 1);
//! assert!(secs_f64!(now) >= 1.0);
//! assert!(millis!(now) >= 1000);
//! assert!(micros!(now) >= 10000);
//! assert!(nanos!(now) >= 100000);
//!```
//!
//! ### Example 4 - Sleep a thread:
//! ```rust
//! # use benri::time::*;
//! # use benri::thread::*;
//! let now = now!();
//!
//! // This sleeps the current thread for 1 second.
//! sleep!(1000);
//!
//! assert!(secs!(now) >= 1);
//! ```
//!
//! ### Example 5 - Exit _all_ threads:
//! ```rust,ignore
//! std::thread::spawn(|| {
//! mass_panic!();
//! }).join().unwrap();
//!
//! // The program will has already exited.
//! // The below statement will never be reached.
//! unsafe { /* do bad things */ }
//! ```
//!
//! ### Example 6 - Send/receive a channel message or `mass_panic!()`:
//! This works with any channel (like [`crossbeam_channel`](https://github.com/crossbeam-rs/crossbeam)) that
//! have the same method names as the `std` channels since the inner macro is calling `.send()` and `.recv()`.
//!
//! ```rust
//! # use benri::sync::*;
//! # use benri::thread::*;
//! let (tx, rx) = std::sync::mpsc::channel::<u8>();
//!
//! std::thread::spawn(move || {
//! send!(tx, 255);
//! }).join().unwrap();
//!
//! assert!(recv!(rx) == 255);
//! ```
//------ Lints
/// Logging functionality using [`log`](https://docs.rs/log)
/// Operators
/// Panic macros
/// `std::sync::*`
/// `std::mem::*`
/// `std::thread::*`
/// `std::time::*`