makes clippy happy
parent
cd05510570
commit
e4475570f3
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
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 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,
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue