From b159cb4439a54cefc9220358068f57e72b335bba Mon Sep 17 00:00:00 2001 From: "Christoph J. Scherr" Date: Tue, 23 Jul 2024 11:27:24 +0200 Subject: [PATCH] refactor: remove ManyWordData ad ManyWords and so on, useless type aliases --- src/game/mod.rs | 5 ++--- src/solve/naive/mod.rs | 6 +++--- src/wlist/mod.rs | 6 +++--- src/wlist/word.rs | 2 -- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/game/mod.rs b/src/game/mod.rs index b778469..497b827 100644 --- a/src/game/mod.rs +++ b/src/game/mod.rs @@ -2,10 +2,9 @@ use core::panic; use std::fmt::Display; use crate::error::*; -use crate::wlist::word::{ManyWordsRef, Word, WordData}; +use crate::wlist::word::{Word, WordData, WordDataRef}; use crate::wlist::WordList; -use libpt::cli::console::StyledObject; use libpt::log::{debug, trace}; pub mod response; @@ -174,7 +173,7 @@ impl<'wl, WL: WordList> Game<'wl, WL> { self.wordlist } - pub(crate) fn made_guesses(&self) -> ManyWordsRef { + pub(crate) fn made_guesses(&self) -> Vec<&Word> { self.responses.iter().map(|r| r.guess()).collect() } } diff --git a/src/solve/naive/mod.rs b/src/solve/naive/mod.rs index 0cb9313..2de11b0 100644 --- a/src/solve/naive/mod.rs +++ b/src/solve/naive/mod.rs @@ -1,7 +1,7 @@ use libpt::log::{info, trace}; -use crate::error::{Error, SolverError, WResult}; -use crate::wlist::word::{ManyWordDatas, Word}; +use crate::error::{SolverError, WResult}; +use crate::wlist::word::{Word, WordData}; use crate::wlist::WordList; use super::{AnyBuiltinSolver, Solver, Status}; @@ -37,7 +37,7 @@ impl<'wl, WL: WordList> Solver<'wl, WL> for NaiveSolver<'wl, WL> { } } trace!("other chars: {:?}", other_chars); - let matches: ManyWordDatas = game + let matches: Vec = game .wordlist() .get_words_matching(pattern) .expect("the solution does not exist in the wordlist") diff --git a/src/wlist/mod.rs b/src/wlist/mod.rs index 0e7a28e..214c082 100644 --- a/src/wlist/mod.rs +++ b/src/wlist/mod.rs @@ -16,7 +16,7 @@ use crate::error::WResult; pub type AnyWordlist = Box; pub trait WordList: Clone + std::fmt::Debug + Default + Sync + Display { - fn solutions(&self) -> ManyWordDatas { + fn solutions(&self) -> Vec { let wmap = self.wordmap().clone(); let threshold = wmap.threshold(); wmap.iter() @@ -88,11 +88,11 @@ pub trait WordList: Clone + std::fmt::Debug + Default + Sync + Display { } buf } - fn get_words_matching(&self, pattern: String) -> WResult { + fn get_words_matching(&self, pattern: String) -> WResult> { let pattern = Regex::new(&pattern)?; let hay = self.raw_wordlist(); let keys = pattern.captures_iter(&hay); - let mut buf = ManyWordDatas::new(); + let mut buf = Vec::new(); for k in keys { let w: WordData = self.wordmap().get(&k[0]).unwrap(); buf.push(w) diff --git a/src/wlist/word.rs b/src/wlist/word.rs index b4f55ce..22d666b 100644 --- a/src/wlist/word.rs +++ b/src/wlist/word.rs @@ -11,8 +11,6 @@ pub type Frequency = f64; pub type Word = String; pub type WordData = (Word, Frequency); pub type WordDataRef<'wl> = (&'wl Word, &'wl Frequency); -pub type ManyWordsRef<'a> = Vec<&'a Word>; -pub type ManyWordDatas = Vec<(Word, Frequency)>; #[derive(Clone)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]