diff options
| author | Aleksey Kladov <aleksey.kladov@gmail.com> | 2021-04-26 19:30:50 +0300 |
|---|---|---|
| committer | Aleksey Kladov <aleksey.kladov@gmail.com> | 2021-04-26 19:30:50 +0300 |
| commit | f06e4b8e74bc2cec1fec4075f64b9909356c2bd3 (patch) | |
| tree | 7ad3bde895f7abf34dc7d2a3db32d1efad6f82a4 | |
| parent | 363cef5c0ebb064a3802fe326205686e6f0c8186 (diff) | |
| download | rust-f06e4b8e74bc2cec1fec4075f64b9909356c2bd3.tar.gz rust-f06e4b8e74bc2cec1fec4075f64b9909356c2bd3.zip | |
minor: simplify
| -rw-r--r-- | crates/stdx/src/lib.rs | 15 |
1 files changed, 3 insertions, 12 deletions
diff --git a/crates/stdx/src/lib.rs b/crates/stdx/src/lib.rs index 857567a853a..1b6211044b4 100644 --- a/crates/stdx/src/lib.rs +++ b/crates/stdx/src/lib.rs @@ -14,18 +14,8 @@ pub fn is_ci() -> bool { #[must_use] pub fn timeit(label: &'static str) -> impl Drop { - struct Guard { - label: &'static str, - start: Instant, - } - - impl Drop for Guard { - fn drop(&mut self) { - eprintln!("{}: {:.2?}", self.label, self.start.elapsed()) - } - } - - Guard { label, start: Instant::now() } + let start = Instant::now(); + defer(move || eprintln!("{}: {:.2?}", label, start.elapsed())) } /// Prints backtrace to stderr, useful for debugging. @@ -179,6 +169,7 @@ where start..start + len } +#[must_use] pub fn defer<F: FnOnce()>(f: F) -> impl Drop { struct D<F: FnOnce()>(Option<F>); impl<F: FnOnce()> Drop for D<F> { |
