From 9eca2a68df8afb078aebda3dfcb3fa6c1b45a5af Mon Sep 17 00:00:00 2001 From: Dmitry Date: Thu, 25 Aug 2022 16:12:47 +0300 Subject: [PATCH] impl FromStr for KeywordType --- src/main.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index fd6a404..65cb3a9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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 { 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