Skip to main content

Crate dropclock

Crate dropclock 

Source
Expand description

§dropclock

CI docs.rs main docs

This crate provides DropClock, a guard type that captures std::time::Instant::now() on creation and, when dropped, passes that instant to a user-provided closure. Useful for timing scopes, logging elapsed durations, or recording metrics without manual bookkeeping.

use dropclock::DropClock;

let _timer = DropClock::new(|start| {
    eprintln!("elapsed: {:?}", start.elapsed());
});
// ... your code here ...
// closure fires when _timer is dropped

§License

Licensed under either of Apache License, Version 2.0 or MIT License at your option.

Structs§

DropClock
Runs a closure on drop, passing the Instant captured at creation.