PlayHead

Struct PlayHead 

Source
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

Source

pub fn new() -> Self

The new counter must start paused since “first play” or any “play after pause” is the same.

Source

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

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.

Source

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

pub fn stop(&mut self) -> bool

The stop function will reset the counter and bring it back to starting state.

Trait Implementations§

Source§

impl Debug for PlayHead

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.