impl FromStr for KeywordType

This commit is contained in:
Dmitry Belyaev 2022-08-25 16:12:47 +03:00
parent 7d17e904fc
commit 9eca2a68df
Signed by: b4tman
GPG Key ID: 41A00BF15EA7E5F3
1 changed files with 8 additions and 5 deletions

View File

@ -8,6 +8,7 @@ use encoding::all::KOI8_R;
use encoding::DecoderTrap;
use rayon::prelude::*;
use std::path::PathBuf;
use std::str::FromStr;
use std::{fs, io};
use textstream::TextReader;
@ -90,10 +91,12 @@ impl Context {
}
}
impl KeywordType {
fn from(pattern: &str) -> KeywordType {
impl FromStr for KeywordType {
type Err = ();
fn from_str(pattern: &str) -> Result<Self, Self::Err> {
use KeywordType::*;
match pattern {
Ok(match pattern {
"Мета:" => Ignore,
"Чемпионат:" | "Пакет:" => Global,
"Тур:" => QuestionPre,
@ -102,7 +105,7 @@ impl KeywordType {
_ => CurrentScope,
// "URL:" | "Ссылка:" | "Дата:" | "Обработан:" | "Автор:" | "Редактор:" | "Копирайт:" | "Инфо:" |
// "Тема:" | "Вид:" | "Тип:" | "Источник:" | "Рейтинг:" | "Комментарий:" | "Комментарии:"
}
})
}
}
@ -152,7 +155,7 @@ fn parse_file(file: impl io::Read) -> Result<json::JsonValue, Box<dyn std::error
ctx.last_keyword_type = ctx.cur_keyword_type;
ctx.last_tag = ctx.cur_tag.clone();
ctx.cur_keyword_type = Some(KeywordType::from(pattern));
ctx.cur_keyword_type = Some(pattern.parse().unwrap());
ctx.cur_tag = pattern.replace(' ', "").replace(':', "");
// remember question id