diff --git a/src/main.rs b/src/main.rs index 909839b..b0da7ea 100644 --- a/src/main.rs +++ b/src/main.rs @@ -55,6 +55,23 @@ struct Context { last_tag: String, } +// check questions before push +trait PushIfValid { + fn is_valid(&self) -> bool; + fn push_if_valid(&mut self, value: json::JsonValue); +} + +impl PushIfValid for json::JsonValue { + fn is_valid(&self) -> bool { + self.has_key("Вопрос") && self.has_key("Ответ") + } + fn push_if_valid(&mut self, value: json::JsonValue) { + if value.is_valid() { + self.push(value).unwrap_or(()) + } + } +} + impl Context { fn new() -> Context { Context { @@ -157,7 +174,7 @@ fn parse_file(file: impl io::Read) -> Result Result