Struct dgews::timer::Timer

source ·
pub struct Timer { /* private fields */ }
Expand description

Timer sturct to retrieve current time

Example

let mut timer = Timer::new();
println!("Time: {}", time.time());
 
std::time::sleep(Duration::from_secs(10));
time.update();
println!("Time: {}", time.time());

Implementations

Creates a new instance of the Time struct

Example
let timer = Timer::new();

Updates the Timer struct’s time

Example
let mut timer = Timer::new();
 
std::time::sleep(Duration::from_secs(5));
 
timer.update();

Retrieves the delta time. (dt() function updates the this instance as well)

Example
let mut timer = Timer::new();
std::time::sleep(Duration::from_secs(10));
timer.update();
std::time::sleep(Duration::from_secs(10));
println!("dt: {}", time.dt());

Retrieves the last time when an instance was updated

Example
let mut timer = Timer::new();
assert_eq!(timer.current_frame(), 0.0);
 
std::time::sleep(Duration::from_secs(10));
assert_eq!(timer.current_frame(), 0.0);
 
timer.update();
assert_neq!(timer.current_frame(), 0.0);

Retrieves the exact current time

Example
let mut timer = Timer::new();
 
for _ in .. {
    println!("Current time: {}", timer.time());
}

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.