Struct stopwatch2::Stopwatch[][src]

pub struct Stopwatch {
    pub spans: Vec<TimeSpan>,
}

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]

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

impl Clone for Stopwatch[src]

impl Debug for Stopwatch[src]

impl Default for Stopwatch[src]

impl Display for Stopwatch[src]

Prints the total time this Stopwatch has run.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.