diff --git a/src/main.rs b/src/main.rs index 2629875..f8a8be0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,9 +26,6 @@ pub struct Args { #[tokio::main] async fn main() { println!("Starting..."); - let corpus = include_str!("/usr/share/dict/words") - .split_whitespace() - .collect::>(); let mut freq = HashMap::>::default(); include_str!("../wap.txt") @@ -69,12 +66,15 @@ async fn main() { } let mut rng = &mut ChaCha8Rng::from_seed(seed); - fn choose_word<'a, 'b>(corpus: &'b [&'b str], rng: &'a mut ChaCha8Rng) -> &'b str { - corpus.choose(rng).unwrap() + fn choose_word<'a, 'b, V>( + freq: &'b HashMap, + rng: &'a mut ChaCha8Rng, + ) -> &'b str { + freq.keys().choose(rng).unwrap() }; let title = (0..rng.gen_range(2..10)) - .map(|_| choose_word(&corpus, rng)) + .map(|_| choose_word(&freq, rng)) .join(" "); let mut word = freq.keys().choose(rng).unwrap(); @@ -88,7 +88,7 @@ async fn main() { .unwrap_or(word); if rng.gen_bool(0.05) { - let url = (0..3).map(|_| choose_word(&corpus, rng)).join("-"); + let url = (0..3).map(|_| choose_word(&freq, rng)).join("-"); content += &format!(" {}", url, word); } else if rng.gen_bool(0.01) { content += ".
";