pub struct PlayHead { /* private fields */ }Expand description
This is one and the only struct we need and have. We do not need to make any of its members public.
Implementations§
Source§impl PlayHead
impl PlayHead
Sourcepub fn new() -> Self
pub fn new() -> Self
The new counter must start paused since “first play” or any “play after pause” is the same.
Sourcepub fn play(&mut self) -> bool
pub fn play(&mut self) -> bool
- There is no diff bw first play and play after pause
- Here we can just set paused to false and thats it
- We can be in either paused mode or play mode, there are just /these 2 states, there is no third state for play head.
- The time is the time spent in play mode excluding the time spent ///in pause mode.
Sourcepub fn time(&self) -> u128
pub fn time(&self) -> u128
This function will just return the time lapsed in milli seconds. if the counter is in paused state then this value will not change.
Sourcepub fn pause(&mut self) -> bool
pub fn pause(&mut self) -> bool
- pause fn is used to pause the counter and before that add the ///current time into old_time.
- the lapsed_time will not be added again if pause is called ///twice since the old_time is updated only when pause is false. ///once it is true the code inside will not run. to make it false ///again we have to go through play.
- here we can just set pause to true and nothing more.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for PlayHead
impl RefUnwindSafe for PlayHead
impl Send for PlayHead
impl Sync for PlayHead
impl Unpin for PlayHead
impl UnwindSafe for PlayHead
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more