std::mem::replace instead of clones
This commit is contained in:
parent
9d1885b245
commit
73f485eb59
12
src/main.rs
12
src/main.rs
@ -201,10 +201,12 @@ impl QuestionsParser {
|
|||||||
}
|
}
|
||||||
/// set current keyword(tag) and type as last, and set new as current
|
/// set current keyword(tag) and type as last, and set new as current
|
||||||
fn set_new_keyword(&mut self, keyword: &str) {
|
fn set_new_keyword(&mut self, keyword: &str) {
|
||||||
self.last_keyword_type = self.cur_keyword_type;
|
self.last_keyword_type =
|
||||||
self.last_tag = self.cur_tag.clone();
|
std::mem::replace(&mut self.cur_keyword_type, Some(keyword.parse().unwrap()));
|
||||||
self.cur_keyword_type = Some(keyword.parse().unwrap());
|
self.last_tag = std::mem::replace(
|
||||||
self.cur_tag = keyword.trim_end().trim_end_matches(':').to_string();
|
&mut self.cur_tag,
|
||||||
|
keyword.trim_end().trim_end_matches(':').to_string(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
/// if line matched keyword
|
/// if line matched keyword
|
||||||
fn on_keyword_match(&mut self, line: &str, keyword: &str) {
|
fn on_keyword_match(&mut self, line: &str, keyword: &str) {
|
||||||
@ -241,7 +243,7 @@ impl QuestionsParser {
|
|||||||
self.clear_current_content();
|
self.clear_current_content();
|
||||||
self.have_new_question = false;
|
self.have_new_question = false;
|
||||||
}
|
}
|
||||||
self.data["Вопросы"] = self.questions.clone();
|
self.data["Вопросы"] = std::mem::replace(&mut self.questions, json::JsonValue::new_array());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// get parsed data
|
/// get parsed data
|
||||||
|
Loading…
Reference in New Issue
Block a user