diff --git a/src/main.rs b/src/main.rs index 54db8f9..5c7551e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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