Skip to main content

crabtalk_proxy/
state.rs

1use crabtalk_core::{Extension, GatewayConfig, Storage};
2use crabtalk_provider::ProviderRegistry;
3use std::{collections::HashMap, sync::Arc};
4
5/// Shared application state passed to all handlers.
6pub struct AppState<S: Storage> {
7    pub registry: ProviderRegistry,
8    pub client: reqwest::Client,
9    pub config: GatewayConfig,
10    pub extensions: Arc<Vec<Box<dyn Extension>>>,
11    pub storage: Arc<S>,
12    /// Precomputed token → key name lookup for O(1) auth.
13    pub key_map: HashMap<String, String>,
14}
15
16impl<S: Storage> Clone for AppState<S> {
17    fn clone(&self) -> Self {
18        Self {
19            registry: self.registry.clone(),
20            client: self.client.clone(),
21            config: self.config.clone(),
22            extensions: self.extensions.clone(),
23            storage: self.storage.clone(),
24            key_map: self.key_map.clone(),
25        }
26    }
27}