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