From 047b5de2d1a01297755f555bdf359ef2762da7f6 Mon Sep 17 00:00:00 2001 From: Mo8it Date: Sat, 29 Oct 2022 00:40:54 +0200 Subject: [PATCH] Split states.rs --- src/{states.rs => captcha_solutions.rs} | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) rename src/{states.rs => captcha_solutions.rs} (80%) diff --git a/src/states.rs b/src/captcha_solutions.rs similarity index 80% rename from src/states.rs rename to src/captcha_solutions.rs index e7ed3fe..c43859c 100644 --- a/src/states.rs +++ b/src/captcha_solutions.rs @@ -1,6 +1,6 @@ -use std::sync::{Arc, Mutex}; +use std::sync::{Arc, Mutex, MutexGuard}; -pub struct CaptchaSolutions { +struct CaptchaSolutions { last_id: u16, solutions: Vec>, } @@ -23,8 +23,12 @@ impl SharedCaptchaSolutions { } } + fn lock(&self) -> MutexGuard { + self.arc.lock().unwrap() + } + pub fn store_solution(&self, solution: &str) -> u16 { - let mut captcha_solutions = self.arc.lock().unwrap(); + let mut captcha_solutions = self.lock(); let new_id = captcha_solutions.last_id.wrapping_add(1); captcha_solutions.last_id = new_id; @@ -36,7 +40,7 @@ impl SharedCaptchaSolutions { pub fn check_answer(&self, id: u16, answer: &str) -> bool { { - let mut captcha_solutions = self.arc.lock().unwrap(); + let mut captcha_solutions = self.lock(); let id = id as usize;