commit fd46f93434ac266dffbd5d520c811237b040d2a6
parent ce510f3169fabd3a7862b2d64be599583b7bf622
Author: tomvig38@gmail.com <tomvig38@gmail.com>
Date: Fri, 15 Oct 2021 14:30:38 +0000
Pli'resist'igi al la erarojn en ParsedDefinition
Diffstat:
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/src/main.rs b/src/main.rs
@@ -77,7 +77,12 @@ struct ParsedDefinition {
}
impl ParsedDefinition {
- pub fn new(lines: &Vec<String>) -> Self {
+ // FARU: revenigi Result<Self>, por erar'traktado
+ pub fn new(lines: &Vec<String>) -> Option<Self> {
+
+ if lines.len() < 3 {
+ return None;
+ }
let mut in_definition = false;
let mut in_traduction = false;
@@ -152,11 +157,11 @@ impl ParsedDefinition {
traductions.push(Traduction(cur_tra_lang, cur_tra));
}
- ParsedDefinition {
+ Some(ParsedDefinition {
radical,
definitions,
traductions,
- }
+ })
}
}
@@ -174,7 +179,7 @@ fn define_word(word: &str) -> Option<String> {
word.to_owned(),
) {
let t = defs.get(0)?;
- let d = ParsedDefinition::new(&t.text);
+ let d = ParsedDefinition::new(&t.text)?;
println!("{:?}", d);
Some(String::from(d.definitions.get(0)?))
} else {