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
sourceimpl Timer
impl Timer
sourcepub fn update(&mut self)
pub fn update(&mut self)
Updates the Timer struct’s time
Example
ⓘ
let mut timer = Timer::new();
std::time::sleep(Duration::from_secs(5));
timer.update();
sourcepub fn dt(&mut self) -> f32
pub fn dt(&mut self) -> f32
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());
sourcepub fn current_frame(&self) -> f32
pub fn current_frame(&self) -> f32
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);
Trait Implementations
impl Copy for Timer
impl StructuralPartialEq for Timer
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
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more