makes clippy happy
parent
cd05510570
commit
e4475570f3
|
@ -14,7 +14,7 @@ pub struct Attempt {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Attempt {
|
impl Attempt {
|
||||||
pub fn from_string(text: &String, answer: &String) -> Self {
|
pub fn from_string(text: &str, answer: &str) -> Self {
|
||||||
let mut output = vec![];
|
let mut output = vec![];
|
||||||
for (n, ch) in text.to_uppercase().chars().enumerate() {
|
for (n, ch) in text.to_uppercase().chars().enumerate() {
|
||||||
let answer_nth = answer
|
let answer_nth = answer
|
||||||
|
|
|
@ -47,7 +47,7 @@ impl Game {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_attempt(&mut self, word: &String) -> InsertionStatus {
|
pub fn add_attempt(&mut self, word: &str) -> InsertionStatus {
|
||||||
let word = word.to_uppercase();
|
let word = word.to_uppercase();
|
||||||
let valid_letters = generate_valid_letters();
|
let valid_letters = generate_valid_letters();
|
||||||
|
|
||||||
|
@ -96,20 +96,15 @@ impl Game {
|
||||||
|
|
||||||
fn generate_result_pattern(&self) -> String {
|
fn generate_result_pattern(&self) -> String {
|
||||||
let mut output = String::new();
|
let mut output = String::new();
|
||||||
for attempt in &self.board {
|
for attempt in self.board.iter().flatten() {
|
||||||
match attempt {
|
for ch in &attempt.chars {
|
||||||
Some(att) => {
|
output.push(match ch.status {
|
||||||
for ch in &att.chars {
|
Status::Found => '🟩',
|
||||||
output.push(match ch.status {
|
Status::Almost => '🟨',
|
||||||
Status::Found => '🟩',
|
Status::NotFound => '⬛',
|
||||||
Status::Almost => '🟨',
|
});
|
||||||
Status::NotFound => '⬛',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
output.push('\n');
|
|
||||||
}
|
}
|
||||||
None => {}
|
output.push('\n');
|
||||||
}
|
|
||||||
}
|
}
|
||||||
output
|
output
|
||||||
}
|
}
|
||||||
|
|
12
src/main.rs
12
src/main.rs
|
@ -63,13 +63,10 @@ async fn get_game(uuid: Uuid) -> Result<Game, ()> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn add_attempt(uuid: Uuid, attempt: &String) -> Option<InsertionStatus> {
|
async fn add_attempt(uuid: Uuid, attempt: &str) -> Option<InsertionStatus> {
|
||||||
let slot_manager_mutex = GAMES.get().unwrap();
|
let slot_manager_mutex = GAMES.get().unwrap();
|
||||||
let mut slot_manager = slot_manager_mutex.lock().await;
|
let mut slot_manager = slot_manager_mutex.lock().await;
|
||||||
match slot_manager.get_game(uuid) {
|
slot_manager.get_game(uuid).map(|game| game.add_attempt(attempt))
|
||||||
Some(game) => Some(game.add_attempt(attempt)),
|
|
||||||
None => None,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[windmark::main]
|
#[windmark::main]
|
||||||
|
@ -165,10 +162,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let attempt = urlencoding::decode(request.parameters.get("attempt").unwrap()).unwrap().to_string();
|
let attempt = urlencoding::decode(request.parameters.get("attempt").unwrap()).unwrap().to_string();
|
||||||
|
|
||||||
let redirect = match Uuid::parse_str(possible_uuid) {
|
let redirect = match Uuid::parse_str(possible_uuid) {
|
||||||
Ok(uuid) => match add_attempt(uuid, &attempt).await {
|
Ok(uuid) => add_attempt(uuid, &attempt).await.is_some(),
|
||||||
Some(_) => true,
|
|
||||||
None => false,
|
|
||||||
},
|
|
||||||
Err(_) => false,
|
Err(_) => false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue