pub struct AppState {
pub config: ConsoleConfig,
pub ws_connections: Arc<RwLock<HashMap<String, usize>>>,
pub rate_limiter: Arc<RwLock<HashMap<String, (u32, Instant)>>>,
pub sessions: Arc<RwLock<HashMap<String, String>>>,
pub metrics_cache: Arc<RwLock<Option<DashboardMetrics>>>,
}Expand description
Shared application state
Fields§
§config: ConsoleConfigConfiguration
ws_connections: Arc<RwLock<HashMap<String, usize>>>Active WebSocket connections (user_id -> connection count)
rate_limiter: Arc<RwLock<HashMap<String, (u32, Instant)>>>Rate limiter state (user_id -> request count)
sessions: Arc<RwLock<HashMap<String, String>>>Session store (session_id -> user_id)
metrics_cache: Arc<RwLock<Option<DashboardMetrics>>>Cached metrics for dashboard
Implementations§
Source§impl AppState
impl AppState
Sourcepub async fn new(config: &ConsoleConfig) -> Result<Self>
pub async fn new(config: &ConsoleConfig) -> Result<Self>
Create new application state
Sourcepub async fn can_create_ws_connection(&self, user_id: &str) -> bool
pub async fn can_create_ws_connection(&self, user_id: &str) -> bool
Check if user can create a new WebSocket connection
Sourcepub async fn increment_ws_connection(&self, user_id: String)
pub async fn increment_ws_connection(&self, user_id: String)
Increment WebSocket connection count for user
Sourcepub async fn decrement_ws_connection(&self, user_id: &str)
pub async fn decrement_ws_connection(&self, user_id: &str)
Decrement WebSocket connection count for user
Sourcepub async fn check_rate_limit(&self, user_id: &str) -> Result<()>
pub async fn check_rate_limit(&self, user_id: &str) -> Result<()>
Check rate limit for user
Sourcepub async fn store_session(&self, session_id: String, user_id: String)
pub async fn store_session(&self, session_id: String, user_id: String)
Store session
Sourcepub async fn get_session(&self, session_id: &str) -> Option<String>
pub async fn get_session(&self, session_id: &str) -> Option<String>
Get user ID from session
Sourcepub async fn remove_session(&self, session_id: &str)
pub async fn remove_session(&self, session_id: &str)
Remove session
Sourcepub async fn update_metrics(&self, metrics: DashboardMetrics)
pub async fn update_metrics(&self, metrics: DashboardMetrics)
Update metrics cache
Sourcepub async fn get_metrics(&self) -> Option<DashboardMetrics>
pub async fn get_metrics(&self) -> Option<DashboardMetrics>
Get cached metrics
Auto Trait Implementations§
impl Freeze for AppState
impl !RefUnwindSafe for AppState
impl Send for AppState
impl Sync for AppState
impl Unpin for AppState
impl !UnwindSafe for AppState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more