generated from PlexSheep/rs-base
refactor: remove ManyWordData ad ManyWords and so on, useless type aliases
This commit is contained in:
parent
0c4adba682
commit
b159cb4439
|
@ -2,10 +2,9 @@ use core::panic;
|
||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
|
|
||||||
use crate::error::*;
|
use crate::error::*;
|
||||||
use crate::wlist::word::{ManyWordsRef, Word, WordData};
|
use crate::wlist::word::{Word, WordData, WordDataRef};
|
||||||
use crate::wlist::WordList;
|
use crate::wlist::WordList;
|
||||||
|
|
||||||
use libpt::cli::console::StyledObject;
|
|
||||||
use libpt::log::{debug, trace};
|
use libpt::log::{debug, trace};
|
||||||
|
|
||||||
pub mod response;
|
pub mod response;
|
||||||
|
@ -174,7 +173,7 @@ impl<'wl, WL: WordList> Game<'wl, WL> {
|
||||||
self.wordlist
|
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()
|
self.responses.iter().map(|r| r.guess()).collect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use libpt::log::{info, trace};
|
use libpt::log::{info, trace};
|
||||||
|
|
||||||
use crate::error::{Error, SolverError, WResult};
|
use crate::error::{SolverError, WResult};
|
||||||
use crate::wlist::word::{ManyWordDatas, Word};
|
use crate::wlist::word::{Word, WordData};
|
||||||
use crate::wlist::WordList;
|
use crate::wlist::WordList;
|
||||||
|
|
||||||
use super::{AnyBuiltinSolver, Solver, Status};
|
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);
|
trace!("other chars: {:?}", other_chars);
|
||||||
let matches: ManyWordDatas = game
|
let matches: Vec<WordData> = game
|
||||||
.wordlist()
|
.wordlist()
|
||||||
.get_words_matching(pattern)
|
.get_words_matching(pattern)
|
||||||
.expect("the solution does not exist in the wordlist")
|
.expect("the solution does not exist in the wordlist")
|
||||||
|
|
|
@ -16,7 +16,7 @@ use crate::error::WResult;
|
||||||
pub type AnyWordlist = Box<dyn WordList>;
|
pub type AnyWordlist = Box<dyn WordList>;
|
||||||
|
|
||||||
pub trait WordList: Clone + std::fmt::Debug + Default + Sync + Display {
|
pub trait WordList: Clone + std::fmt::Debug + Default + Sync + Display {
|
||||||
fn solutions(&self) -> ManyWordDatas {
|
fn solutions(&self) -> Vec<WordData> {
|
||||||
let wmap = self.wordmap().clone();
|
let wmap = self.wordmap().clone();
|
||||||
let threshold = wmap.threshold();
|
let threshold = wmap.threshold();
|
||||||
wmap.iter()
|
wmap.iter()
|
||||||
|
@ -88,11 +88,11 @@ pub trait WordList: Clone + std::fmt::Debug + Default + Sync + Display {
|
||||||
}
|
}
|
||||||
buf
|
buf
|
||||||
}
|
}
|
||||||
fn get_words_matching(&self, pattern: String) -> WResult<ManyWordDatas> {
|
fn get_words_matching(&self, pattern: String) -> WResult<Vec<WordData>> {
|
||||||
let pattern = Regex::new(&pattern)?;
|
let pattern = Regex::new(&pattern)?;
|
||||||
let hay = self.raw_wordlist();
|
let hay = self.raw_wordlist();
|
||||||
let keys = pattern.captures_iter(&hay);
|
let keys = pattern.captures_iter(&hay);
|
||||||
let mut buf = ManyWordDatas::new();
|
let mut buf = Vec::new();
|
||||||
for k in keys {
|
for k in keys {
|
||||||
let w: WordData = self.wordmap().get(&k[0]).unwrap();
|
let w: WordData = self.wordmap().get(&k[0]).unwrap();
|
||||||
buf.push(w)
|
buf.push(w)
|
||||||
|
|
|
@ -11,8 +11,6 @@ pub type Frequency = f64;
|
||||||
pub type Word = String;
|
pub type Word = String;
|
||||||
pub type WordData = (Word, Frequency);
|
pub type WordData = (Word, Frequency);
|
||||||
pub type WordDataRef<'wl> = (&'wl Word, &'wl Frequency);
|
pub type WordDataRef<'wl> = (&'wl Word, &'wl Frequency);
|
||||||
pub type ManyWordsRef<'a> = Vec<&'a Word>;
|
|
||||||
pub type ManyWordDatas = Vec<(Word, Frequency)>;
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||||
|
|
Loading…
Reference in New Issue