un/pause mutate self instead of taking ownership (uses Copy)
This commit is contained in:
parent
d58af1f2b2
commit
a98b71f0da
24
src/timer.rs
24
src/timer.rs
@ -199,16 +199,18 @@ impl<T:TimerState> Timer<T>{
|
||||
Self::Unpaused(timer)=>timer.set_time(time,new_time),
|
||||
}
|
||||
}
|
||||
pub fn pause(self,time:Time)->Result<TimerFixed<T,Paused>,Error>{
|
||||
match self{
|
||||
Self::Paused(_)=>Err(Error::AlreadyPaused),
|
||||
Self::Unpaused(timer)=>Ok(timer.into_paused(time)),
|
||||
}
|
||||
}
|
||||
pub fn unpause(self,time:Time)->Result<TimerFixed<T,Unpaused>,Error>{
|
||||
match self{
|
||||
Self::Paused(timer)=>Ok(timer.into_unpaused(time)),
|
||||
Self::Unpaused(_)=>Err(Error::AlreadyUnpaused),
|
||||
}
|
||||
pub fn pause(&mut self,time:Time)->Result<(),Error>{
|
||||
*self=match *self{
|
||||
Self::Paused(_)=>return Err(Error::AlreadyPaused),
|
||||
Self::Unpaused(timer)=>Self::Paused(timer.into_paused(time)),
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
pub fn unpause(&mut self,time:Time)->Result<(),Error>{
|
||||
*self=match *self{
|
||||
Self::Paused(timer)=>Self::Unpaused(timer.into_unpaused(time)),
|
||||
Self::Unpaused(_)=>return Err(Error::AlreadyUnpaused),
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user