From 453ba51e78024fed7d22f984959b050182badffd Mon Sep 17 00:00:00 2001 From: Jomar Milan Date: Sat, 30 May 2026 00:09:59 -0700 Subject: Store sessions in a hash map --- src/main.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 422e784..cc8cc34 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,6 @@ mod template; use std::collections::HashMap; use std::net::SocketAddr; -use std::ops::{Deref, Index}; use std::sync::{Arc, Mutex}; use std::time::{SystemTime, UNIX_EPOCH}; use askama::Template; @@ -21,13 +20,13 @@ use crate::template::IndexTemplate; struct Asset; struct AppState { - sessions: Mutex> + sessions: Mutex> } impl AppState { fn new() -> Self { AppState { - sessions: Mutex::new(Vec::new()) + sessions: Mutex::new(HashMap::new()) } } } @@ -75,7 +74,7 @@ async fn visit_session(Path(id): Path, Query(query): Query { if passcode.map(|passcode| passcode.as_str() == session.passcode).unwrap_or(false) { (StatusCode::OK, "hi").into_response() @@ -93,14 +92,11 @@ async fn create_session(Path(id): Path, Query(query): Query