aboutsummaryrefslogtreecommitdiff
path: root/crates/stdx
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2021-04-26 17:30:50 +0100
committerAleksey Kladov <[email protected]>2021-04-26 17:30:50 +0100
commitf06e4b8e74bc2cec1fec4075f64b9909356c2bd3 (patch)
tree7ad3bde895f7abf34dc7d2a3db32d1efad6f82a4 /crates/stdx
parent363cef5c0ebb064a3802fe326205686e6f0c8186 (diff)
minor: simplify
Diffstat (limited to 'crates/stdx')
-rw-r--r--crates/stdx/src/lib.rs15
1 files changed, 3 insertions, 12 deletions
diff --git a/crates/stdx/src/lib.rs b/crates/stdx/src/lib.rs
index 857567a85..1b6211044 100644
--- a/crates/stdx/src/lib.rs
+++ b/crates/stdx/src/lib.rs
@@ -14,18 +14,8 @@ pub fn is_ci() -> bool {
14 14
15#[must_use] 15#[must_use]
16pub fn timeit(label: &'static str) -> impl Drop { 16pub fn timeit(label: &'static str) -> impl Drop {
17 struct Guard { 17 let start = Instant::now();
18 label: &'static str, 18 defer(move || eprintln!("{}: {:.2?}", label, start.elapsed()))
19 start: Instant,
20 }
21
22 impl Drop for Guard {
23 fn drop(&mut self) {
24 eprintln!("{}: {:.2?}", self.label, self.start.elapsed())
25 }
26 }
27
28 Guard { label, start: Instant::now() }
29} 19}
30 20
31/// Prints backtrace to stderr, useful for debugging. 21/// Prints backtrace to stderr, useful for debugging.
@@ -179,6 +169,7 @@ where
179 start..start + len 169 start..start + len
180} 170}
181 171
172#[must_use]
182pub fn defer<F: FnOnce()>(f: F) -> impl Drop { 173pub fn defer<F: FnOnce()>(f: F) -> impl Drop {
183 struct D<F: FnOnce()>(Option<F>); 174 struct D<F: FnOnce()>(Option<F>);
184 impl<F: FnOnce()> Drop for D<F> { 175 impl<F: FnOnce()> Drop for D<F> {