Browse Source

Implement Dictionary::load_from_iterable

Blallo 4 years ago
parent
commit
c9c21d7dfd
1 changed files with 11 additions and 0 deletions
  1. 11 0
      src/main.rs

+ 11 - 0
src/main.rs

@@ -14,6 +14,17 @@ struct Dictionary {
     iter_position: usize,
 }
 
+impl Dictionary {
+    fn load_from_iterable(
+        &mut self,
+        lines: impl Iterator<Item = Result<String, Error>>,
+    ) -> Result<(), std::io::Error> {
+        lines
+            .map(|line| line.and_then(|line_str| Ok(self.words.push(line_str))))
+            .collect()
+    }
+}
+
 /*impl Dictionary {
     fn default() -> Dictionary {
         Dictionary{words: vec![], iter_position: 0}