Split states.rs
This commit is contained in:
parent
764ebab7b5
commit
047b5de2d1
1 changed files with 8 additions and 4 deletions
|
@ -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<Option<String>>,
|
||||
}
|
||||
|
@ -23,8 +23,12 @@ impl SharedCaptchaSolutions {
|
|||
}
|
||||
}
|
||||
|
||||
fn lock(&self) -> MutexGuard<CaptchaSolutions> {
|
||||
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;
|
||||
|
Loading…
Reference in a new issue