Skip to content

Commit f06e4b8

Browse files
committed
minor: simplify
1 parent 363cef5 commit f06e4b8

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

crates/stdx/src/lib.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,8 @@ pub fn is_ci() -> bool {
1414

1515
#[must_use]
1616
pub fn timeit(label: &'static str) -> impl Drop {
17-
struct Guard {
18-
label: &'static str,
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() }
17+
let start = Instant::now();
18+
defer(move || eprintln!("{}: {:.2?}", label, start.elapsed()))
2919
}
3020

3121
/// Prints backtrace to stderr, useful for debugging.
@@ -179,6 +169,7 @@ where
179169
start..start + len
180170
}
181171

172+
#[must_use]
182173
pub fn defer<F: FnOnce()>(f: F) -> impl Drop {
183174
struct D<F: FnOnce()>(Option<F>);
184175
impl<F: FnOnce()> Drop for D<F> {

0 commit comments

Comments
 (0)