Struct climer::timer::Timer

source ·
pub struct Timer {
    pub state: TimerState,
    /* private fields */
}

Fields§

§state: TimerState

Implementations§

source§

impl Timer

source

pub fn builder() -> TimerBuilder

Returns a new TimerBuilder.

source

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.

source

pub fn set_target_time(&mut self, target_time: Time)

Set a new target Time.

source

pub fn set_continue_after_finish(&mut self, continue_after_finish: bool)

source

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.

source

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.

source

pub fn clear_start_time(&mut self)

Removes the start Time.

source

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.

source

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.

source

pub fn stop(&mut self) -> ClimerResult

Stops the timer, after it has been started using the start method.

source

pub fn pause(&mut self) -> ClimerResult

Pauses the timer.

source

pub fn resume(&mut self) -> ClimerResult

Resumes the timer from a paused state.

source

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.

source

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).

source

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.

source

pub fn finish(&mut self) -> ClimerResult

Finish the timer.

Trait Implementations§

source§

impl Clone for Timer

source§

fn clone(&self) -> Timer

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Default for Timer

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl RefUnwindSafe for Timer

§

impl Send for Timer

§

impl Sync for Timer

§

impl Unpin for Timer

§

impl UnwindSafe for Timer

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.