From befca9901950679db0ee987513182e7122717b75 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Sat, 27 Jul 2019 11:30:40 +0300 Subject: [PATCH] impl Context::new --- src/main.rs | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/main.rs b/src/main.rs index 95841c4..418f6f0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -70,6 +70,24 @@ struct Context { last_tag: String, } +impl Context { + fn new() -> Context { + Context { + data: json::JsonValue::new_object(), + questions: json::JsonValue::new_array(), + cur_keyword_type: None, + cur_question: json::JsonValue::new_object(), + cur_question_pre: json::JsonValue::new_object(), + cur_tag: String::new(), + cur_content: Vec::::new(), + cur_scope: DataScope::Global, + have_new_question: false, + last_keyword_type: None, + last_tag: String::new(), + } + } +} + fn parse_file(file: impl io::Read) -> Result> { let buf = io::BufReader::new(file); let reader = TextReader::new(buf, KOI8_R, DecoderTrap::Ignore); @@ -99,20 +117,8 @@ fn parse_file(file: impl io::Read) -> Result::new(), - cur_scope: DataScope::Global, - have_new_question: false, - last_keyword_type: None, - last_tag: String::new(), - }; + + let mut context = Context::new(); let mut ctx = &mut context; reader