pub struct Timer {
pub state: TimerState,
/* private fields */
}
Fields§
§state: TimerState
Implementations§
source§impl Timer
impl Timer
sourcepub fn builder() -> TimerBuilder
pub fn builder() -> TimerBuilder
Returns a new TimerBuilder
.
sourcepub fn new(target_time: Option<Time>, output: Option<Output>) -> Self
pub fn new(target_time: Option<Time>, output: Option<Output>) -> Self
Create a new Timer
with the given optional arguments:
target_time
(Time
), and output
(Output
).
If a target_time
is given, then the timer will act more like a countdown.
If no target_time
is given, then the timer will act more like a stopwatch;
it will never finish naturally, so instead you need to stop the timer when necessary.
sourcepub fn set_target_time(&mut self, target_time: Time)
pub fn set_target_time(&mut self, target_time: Time)
Set a new target Time
.
pub fn set_continue_after_finish(&mut self, continue_after_finish: bool)
sourcepub fn clear_target_time(&mut self)
pub fn clear_target_time(&mut self)
Removes the target Time
.
If the timer has no target time, then it acts like a stopwatch,
endlessly counting upwards.
sourcepub fn set_start_time(&mut self, start_time: Time)
pub fn set_start_time(&mut self, start_time: Time)
Set the starting time
value.
Used for starting the timer with a starting time other than 0.
sourcepub fn clear_start_time(&mut self)
pub fn clear_start_time(&mut self)
Removes the start Time
.
sourcepub fn run(&mut self) -> ClimerResult
pub fn run(&mut self) -> ClimerResult
Run the timer.
This will lock the current thread until the time is up.
If you want to update the timer yourself somewhere else,
then don’t call this method, instead call the update
method to update the timer.
sourcepub fn start(&mut self) -> ClimerResult
pub fn start(&mut self) -> ClimerResult
Start the timer. Do not call this method directly if you are using the run
method.
Only call this method if you intend to update the timer manually
by calling the update
method.
The start
method can also be used as a restart.
sourcepub fn stop(&mut self) -> ClimerResult
pub fn stop(&mut self) -> ClimerResult
Stops the timer, after it has been started using the start
method.
sourcepub fn pause(&mut self) -> ClimerResult
pub fn pause(&mut self) -> ClimerResult
Pauses the timer.
sourcepub fn resume(&mut self) -> ClimerResult
pub fn resume(&mut self) -> ClimerResult
Resumes the timer from a paused state.
sourcepub fn update(&mut self) -> ClimerResult
pub fn update(&mut self) -> ClimerResult
Updates the timer.
This will also attempt to write the remaining time to stdout or to a file,
using the Output
of this Timer
.
sourcepub fn print_output(&mut self) -> ClimerResult
pub fn print_output(&mut self) -> ClimerResult
Print the current time to stdout or to a file using this timer’s Output
(if output exists).
sourcepub fn time_output(&self) -> Time
pub fn time_output(&self) -> Time
Returns a Time
.
If a target_time
was given, then it returns the remaining time
until the timer finishes;
if no target_time
was given, then it returns the time since the timer was started.
sourcepub fn finish(&mut self) -> ClimerResult
pub fn finish(&mut self) -> ClimerResult
Finish the timer.