30 lines
730 B
Rust
30 lines
730 B
Rust
use std::{fs, path::Path};
|
|
|
|
use rand::{seq::SliceRandom, thread_rng};
|
|
|
|
pub fn load(path: impl AsRef<Path>, width: usize) -> Vec<String> {
|
|
let content = fs::read_to_string(path).expect("Can read file.");
|
|
content
|
|
.lines()
|
|
.filter(|w| w.len() == width)
|
|
.map(|l| l.to_string())
|
|
.collect()
|
|
}
|
|
|
|
pub fn francais(width: usize) -> Vec<String> {
|
|
let raw = include_str!("../data/francais.txt");
|
|
raw.lines()
|
|
.filter(|w| w.len() == width)
|
|
.map(|l| l.to_string())
|
|
.collect()
|
|
}
|
|
pub fn gutenberg(width: usize) -> Vec<String> {
|
|
let raw = include_str!("../data/gutenberg.txt");
|
|
let mut res = raw
|
|
.lines()
|
|
.filter(|w| w.len() == width)
|
|
.map(|l| l.to_string())
|
|
.collect::<Vec<_>>();
|
|
res.shuffle(&mut thread_rng());
|
|
res
|
|
}
|