use std::io::{self, BufReader, BufRead}; use std::collections::HashSet; use std::path::Path; use std::fs::File; #[derive(Debug)] pub struct CommonWords(HashSet); impl CommonWords { pub fn from_file

(path: P) -> io::Result where P: AsRef { let file = File::open(path)?; let file = BufReader::new(file); let mut set = HashSet::new(); for line in file.lines().filter_map(|l| l.ok()) { let word = line.trim().to_owned(); set.insert(word); } Ok(CommonWords(set)) } pub fn contains(&self, word: &str) -> bool { self.0.contains(word) } }