Struct stopwatch2::Stopwatch [−][src]
A stopwatch used to calculate time differences.
Example
use stopwatch2::*; let mut s = Stopwatch::default(); s.start(); // Starts the stopwatch. s.start(); // Creates a new time span, which are commonly called "splits". s.stop(); // Stops the stopwatch. println!("{}", s); // Prints the total time. println!("{:?}", s); // Prints the different time spans as debug information. let total_time = s.elapsed(); // returns the total time as a Duration. for span in &s.spans { println!("{:?} -> {:?}", span.start, span.stop); } s.spans.clear(); // Reset the stopwatch. println!("{}", s); // Prints the total time. println!("{:?}", s); // Prints the different time spans as debug information.
Fields
spans: Vec<TimeSpan>
All the time spans that this stopwatch has been or is still running. Only the last timespan is allowed to have no stop value, which means it is still active.
Implementations
impl Stopwatch
[src]
impl Stopwatch
[src]pub fn start(&mut self) -> Option<TimeSpan>
[src]
Starts the stopwatch.
If it is already started, it will create a new split. This means it will stop and start the stopwatch, creating a new TimeSpan in the process.
pub fn stop(&mut self) -> Option<TimeSpan>
[src]
Stops the stopwatch without resetting it.
pub fn is_running(&self) -> bool
[src]
Returns whether the stopwatch is running.
pub fn elapsed(&self) -> Duration
[src]
Returns the total elapsed time accumulated inside of this stopwatch.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Stopwatch
impl RefUnwindSafe for Stopwatch
impl UnwindSafe for Stopwatch
impl UnwindSafe for Stopwatch