std::mem::replace instead of clones

This commit is contained in:
Dmitry Belyaev 2022-09-23 22:50:42 +03:00
parent 9d1885b245
commit 73f485eb59
Signed by: b4tman
GPG Key ID: 41A00BF15EA7E5F3

View File

@ -201,10 +201,12 @@ impl QuestionsParser {
}
/// set current keyword(tag) and type as last, and set new as current
fn set_new_keyword(&mut self, keyword: &str) {
self.last_keyword_type = self.cur_keyword_type;
self.last_tag = self.cur_tag.clone();
self.cur_keyword_type = Some(keyword.parse().unwrap());
self.cur_tag = keyword.trim_end().trim_end_matches(':').to_string();
self.last_keyword_type =
std::mem::replace(&mut self.cur_keyword_type, Some(keyword.parse().unwrap()));
self.last_tag = std::mem::replace(
&mut self.cur_tag,
keyword.trim_end().trim_end_matches(':').to_string(),
);
}
/// if line matched keyword
fn on_keyword_match(&mut self, line: &str, keyword: &str) {
@ -241,7 +243,7 @@ impl QuestionsParser {
self.clear_current_content();
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