testutils/lib.rs
1#![cfg_attr(not(feature = "std"), no_std)]
2#![cfg_attr(docsrs, feature(doc_cfg))]
3
4/*!
5## Features
6
7- **std**
8 Enables standard library support. When enabled, the crate cannot be used in `no_std` environments.
9
10- **bool_ext**
11 - Adds `.then_ok_or_else(||{err})` & `.then_ok_or(err)` method for `bool` type
12
13- **print_ext**
14 - Provides some printing helpers.
15
16- **re_exports_tap**
17 - `pub use tap`
18
19- **os_cmd**
20 Configurable command builders:
21 - Preconfigured cargo command structs (e.g., `CargoDoc`, `CargoCmd`)
22 - Cross-platform command execution utilities
23*/
24extern crate alloc;
25
26#[cfg(feature = "os_cmd")]
27pub mod os_cmd;
28
29mod macros;
30
31#[cfg(feature = "const_macros")]
32pub mod const_macros;
33
34#[cfg(feature = "bool_ext")]
35pub mod bool_ext;
36
37#[cfg(feature = "print_ext")]
38pub mod print_ext;
39
40#[cfg(feature = "re_exports_tap")]
41pub use tap;
42
43/// Runs the given function and prints the elapsed time.
44/// It supports stable Rust.
45///
46/// ## Example
47///
48/// ```ignore
49/// fn bench_foo() {
50/// testutils::simple_benchmark(|| {
51/// foo() // Your code here...
52/// })
53/// }
54/// ```
55#[cfg(feature = "std")]
56pub fn simple_benchmark<U, F: FnOnce() -> U>(f: F) {
57 let start = std::time::Instant::now();
58 f();
59 let elapsed = start.elapsed();
60
61 eprintln!("Time taken: {elapsed:?}")
62}