From a98b71f0dada0c49ccb8eb7e1a26ca7db57404a1 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Wed, 31 Jul 2024 18:39:15 -0700 Subject: [PATCH] un/pause mutate self instead of taking ownership (uses Copy) --- src/timer.rs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/timer.rs b/src/timer.rs index 5e2308b..ccb636d 100644 --- a/src/timer.rs +++ b/src/timer.rs @@ -199,16 +199,18 @@ impl Timer{ Self::Unpaused(timer)=>timer.set_time(time,new_time), } } - pub fn pause(self,time:Time)->Result,Error>{ - match self{ - Self::Paused(_)=>Err(Error::AlreadyPaused), - Self::Unpaused(timer)=>Ok(timer.into_paused(time)), - } + 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(self,time:Time)->Result,Error>{ - match self{ - Self::Paused(timer)=>Ok(timer.into_unpaused(time)), - Self::Unpaused(_)=>Err(Error::AlreadyUnpaused), - } + 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(()) } }