Created
June 6, 2015 14:44
-
-
Save fenhl/579c0380d5c4bdbedb1b to your computer and use it in GitHub Desktop.
jqsh::parser::Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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