use std::fs::File;
use std::io::{self, BufRead, BufReader};
#[derive(Debug)]
pub struct GargleBargle(pub Vec<String>);
impl GargleBargle {
pub fn load_words(file: &str) -> Result<Self, io::Error> {
let f = File::open(file)?;
let reader = BufReader::new(f);
#[allow(clippy::lines_filter_map_ok)]
Ok(Self(reader.lines().filter_map(|word| word.ok()).collect()))
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_load_error() {
let result = GargleBargle::load_words("/does-not-exist");
assert!(result.is_err());
}
#[test]
fn test_load_ok() {
let result = GargleBargle::load_words("README.md");
assert!(result.is_ok());
}
}