Skip to content

Instantly share code, notes, and snippets.

@fenhl
Created June 6, 2015 14:44
Show Gist options
  • Save fenhl/579c0380d5c4bdbedb1b to your computer and use it in GitHub Desktop.
Save fenhl/579c0380d5c4bdbedb1b to your computer and use it in GitHub Desktop.
jqsh::parser::Code
impl Clone for Code {
fn clone(&self) -> Code {
let mut lock = self.0.lock().unwrap();
match *&mut *lock {
CodeVariant::Empty => Code(Mutex::new(CodeVariant::Empty)),
CodeVariant::UString { ref s, .. } => Code(Mutex::new(CodeVariant::UString { s: s.clone(), peek_index: 0 })),
CodeVariant::UStringIter(_) => {
if let CodeVariant::UStringIter(it) = mem::replace(&mut *lock, CodeVariant::Mutation) {
let s = it.collect::<UString>();
*lock = CodeVariant::UString { s: s.clone(), peek_index: 0 };
Code(Mutex::new(CodeVariant::UString { s: s, peek_index: 0 }))
} else {
unreachable!()
}
}
CodeVariant::Mutation => panic!("code mutex has been emptied")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment