use Copy instead of unsafe
This commit is contained in:
parent
91608d5100
commit
b5b20e0dba
12
src/run.rs
12
src/run.rs
@ -79,24 +79,18 @@ 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
|
|
||||||
unsafe{
|
|
||||||
let state=std::ptr::read(dest);
|
|
||||||
match state{
|
|
||||||
RunState::Created=>Err(Error::NotStarted),
|
RunState::Created=>Err(Error::NotStarted),
|
||||||
RunState::Started{timer}=>{
|
RunState::Started{timer}=>{
|
||||||
let src=RunState::Finished{
|
self.state=RunState::Finished{
|
||||||
timer:timer.pause(time),
|
timer:timer.pause(time),
|
||||||
};
|
};
|
||||||
std::ptr::write(dest,src);
|
|
||||||
Ok(())
|
Ok(())
|
||||||
},
|
},
|
||||||
RunState::Finished{..}=>Err(Error::AlreadyFinished),
|
RunState::Finished{..}=>Err(Error::AlreadyFinished),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
pub fn flag(&mut self,flag_reason:FlagReason){
|
pub fn flag(&mut self,flag_reason:FlagReason){
|
||||||
//don't replace the first reason the run was flagged
|
//don't replace the first reason the run was flagged
|
||||||
if self.flagged.is_none(){
|
if self.flagged.is_none(){
|
||||||
|
Loading…
Reference in New Issue
Block a user