use Copy instead of unsafe
This commit is contained in:
parent
91608d5100
commit
b5b20e0dba
26
src/run.rs
26
src/run.rs
@ -79,22 +79,16 @@ impl Run{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn finish(&mut self,time:Time)->Result<(),Error>{
|
pub fn finish(&mut self,time:Time)->Result<(),Error>{
|
||||||
//code based on std::mem::replace
|
//this uses Copy
|
||||||
let dest=&mut self.state;
|
match &self.state{
|
||||||
//let's ignore ownership rules for a moment
|
RunState::Created=>Err(Error::NotStarted),
|
||||||
unsafe{
|
RunState::Started{timer}=>{
|
||||||
let state=std::ptr::read(dest);
|
self.state=RunState::Finished{
|
||||||
match state{
|
timer:timer.pause(time),
|
||||||
RunState::Created=>Err(Error::NotStarted),
|
};
|
||||||
RunState::Started{timer}=>{
|
Ok(())
|
||||||
let src=RunState::Finished{
|
},
|
||||||
timer:timer.pause(time),
|
RunState::Finished{..}=>Err(Error::AlreadyFinished),
|
||||||
};
|
|
||||||
std::ptr::write(dest,src);
|
|
||||||
Ok(())
|
|
||||||
},
|
|
||||||
RunState::Finished{..}=>Err(Error::AlreadyFinished),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn flag(&mut self,flag_reason:FlagReason){
|
pub fn flag(&mut self,flag_reason:FlagReason){
|
||||||
|
Loading…
Reference in New Issue
Block a user