diff --git a/src/attempt.rs b/src/attempt.rs index 5c1101e..3f9c45d 100644 --- a/src/attempt.rs +++ b/src/attempt.rs @@ -14,7 +14,7 @@ pub struct 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![]; for (n, ch) in text.to_uppercase().chars().enumerate() { let answer_nth = answer diff --git a/src/gameslot.rs b/src/gameslot.rs index 0f11deb..fa71522 100644 --- a/src/gameslot.rs +++ b/src/gameslot.rs @@ -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 valid_letters = generate_valid_letters(); @@ -96,20 +96,15 @@ impl Game { fn generate_result_pattern(&self) -> String { let mut output = String::new(); - for attempt in &self.board { - match attempt { - Some(att) => { - for ch in &att.chars { - output.push(match ch.status { - Status::Found => '🟩', - Status::Almost => '🟨', - Status::NotFound => '⬛', - }); - } - output.push('\n'); + for attempt in self.board.iter().flatten() { + for ch in &attempt.chars { + output.push(match ch.status { + Status::Found => '🟩', + Status::Almost => '🟨', + Status::NotFound => '⬛', + }); } - None => {} - } + output.push('\n'); } output } diff --git a/src/main.rs b/src/main.rs index 96ad716..cc7f057 100644 --- a/src/main.rs +++ b/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 mut slot_manager = slot_manager_mutex.lock().await; - match slot_manager.get_game(uuid) { - Some(game) => Some(game.add_attempt(attempt)), - None => None, - } + slot_manager.get_game(uuid).map(|game| game.add_attempt(attempt)) } #[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 redirect = match Uuid::parse_str(possible_uuid) { - Ok(uuid) => match add_attempt(uuid, &attempt).await { - Some(_) => true, - None => false, - }, + Ok(uuid) => add_attempt(uuid, &attempt).await.is_some(), Err(_) => false, };