Stopwatch structv0.1.0
pub struct Stopwatch {
// private fields
}
Copy, owning nothing; a copy is an independent stopwatch with the same history. Starts stopped at zero. The
elapsed time is the sum of every stretch between a start and a stop, plus the current stretch while running.
Constructors
Stopwatch
pub func Stopwatch() -> Stopwatch
A stopwatch that is stopped and reads zero. Cannot fail and does not read the clock.
Returns: a stopped stopwatch at zero
Associated functions
StartNew
pub func StartNew() -> Stopwatch
A stopwatch that reads zero and is already running. Reads the clock once. Cannot fail.
Returns: a running stopwatch, started now
Methods
Start
pub func Start(self: &var Stopwatch)
Starts the stopwatch, or resumes it from the total it already holds. Does nothing when it is already running, so a second start does not restart the current stretch. Cannot fail.
Stop
pub func Stop(self: &var Stopwatch)
Stops the stopwatch, adding the current stretch to its total. Does nothing when it is already stopped. The total then stays fixed until the stopwatch is started again. Cannot fail.
Reset
pub func Reset(self: &var Stopwatch)
Stops the stopwatch and sets it back to zero, clearing the laps. Cannot fail and does not read the clock.
Restart
pub func Restart(self: &var Stopwatch)
Sets the stopwatch back to zero, clearing the laps, and starts it.
The same as Reset followed by Start, with one clock reading. Cannot fail.
IsRunning
pub func IsRunning(self: &Stopwatch) -> bool
Whether the stopwatch is running. Cannot fail and does not read the clock.
Returns: true between a start and the next stop or reset
Elapsed
pub func Elapsed(self: &Stopwatch) -> Duration
The total elapsed time: every finished stretch, plus the current one while running. Reading it does not stop or otherwise change the stopwatch. Reads the clock only while running, and two readings of a stopped stopwatch are equal. Cannot fail.
Returns: the elapsed time, never negative
Lap
pub func Lap(self: &var Stopwatch) -> Duration
Ends the current lap and returns its length: the elapsed time since the previous lap ended, or since zero. The stopwatch keeps running or stays stopped as it was; only time the stopwatch counted is part of a lap, so a lap spanning a pause excludes the pause. The laps since the last reset add up to the elapsed time at the end of the last one. Cannot fail.
Returns: the length of the lap just ended, never negative