From 73f485eb59dea2600ddac06a81366022c0130d0b Mon Sep 17 00:00:00 2001 From: Dmitry Date: Fri, 23 Sep 2022 22:50:42 +0300 Subject: [PATCH] std::mem::replace instead of clones --- src/main.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) 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