pub struct AppState {Show 26 fields
pub config: Arc<Config>,
pub store: DatabaseAdapter,
pub cache: WhatCache,
pub components: Arc<ComponentRegistry>,
pub engine: Arc<RenderEngine>,
pub root: PathBuf,
pub content_dir: PathBuf,
pub sessions: Option<SessionBackend>,
pub auth: AuthHandler,
pub dev_mode: bool,
pub css_mode: CssMode,
pub live_reload_tx: Option<Sender<LiveReloadMessage>>,
pub wired_tx: Sender<WiredMessage>,
pub wired_scopes: Arc<RwLock<HashMap<String, WiredScope>>>,
pub app_scopes: Arc<RwLock<HashMap<String, WiredScope>>>,
pub policies: Arc<PolicyRegistry>,
pub data_source_loaded: Arc<RwLock<HashMap<String, Instant>>>,
pub rate_limiters: Option<RateLimiters>,
pub log_level: String,
pub jobs: JobQueue,
pub http_client: Client,
pub upload_backend: Option<UploadBackend>,
pub datasources: HashMap<String, Datasource>,
pub wired_client_count: Arc<AtomicUsize>,
pub validated_actions: Arc<RwLock<HashSet<String>>>,
pub activity_log: Arc<Mutex<VecDeque<ActivityEvent>>>,
}Expand description
Application state shared across handlers
Fields§
§config: Arc<Config>Configuration
store: DatabaseAdapterData store (SQLite, D1, or Supabase — configured via [database] in what.toml)
cache: WhatCacheCache
components: Arc<ComponentRegistry>Component registry
engine: Arc<RenderEngine>Render engine
root: PathBufProject root directory
content_dir: PathBufResolved content directory path (root + “site” or “pages”)
sessions: Option<SessionBackend>Session store (pluggable: SQLite or Cloudflare KV)
auth: AuthHandlerAuthentication handler
dev_mode: boolDevelopment mode flag
css_mode: CssModeFramework stylesheet mode ([server] css in what.toml), validated at startup
live_reload_tx: Option<Sender<LiveReloadMessage>>Live reload broadcast sender (only active in dev mode)
wired_tx: Sender<WiredMessage>Wired state broadcast sender (real-time push with scope filtering)
wired_scopes: Arc<RwLock<HashMap<String, WiredScope>>>Scope registry for wired variables (rebuilt on application.what reload)
app_scopes: Arc<RwLock<HashMap<String, WiredScope>>>Scope registry for application variables — write-gates app.* mutations
declared with [role] brackets (rebuilt on application.what reload)
policies: Arc<PolicyRegistry>Compiled collection authorization policies (from [collections.*])
data_source_loaded: Arc<RwLock<HashMap<String, Instant>>>Last refresh timestamps for configured data sources
rate_limiters: Option<RateLimiters>Rate limiters for login, upload, and action endpoints
log_level: StringLog level string for debug meta injection (dev mode only)
jobs: JobQueueBackground job queue for async operations (session cleanup, email, etc.)
http_client: ClientShared HTTP client with configurable timeout for external fetch requests
upload_backend: Option<UploadBackend>Upload storage backend (local filesystem or Cloudflare R2)
datasources: HashMap<String, Datasource>Named datasources — multiple backends accessible via dsn:name in fetch directives
wired_client_count: Arc<AtomicUsize>Number of currently connected wired WebSocket clients
validated_actions: Arc<RwLock<HashSet<String>>>Registry of form action URLs that require validation (populated at render time).
When a form with w-validate is rendered, its action is recorded here.
On submission, if the action is registered but w-rules is missing, the request is rejected.
activity_log: Arc<Mutex<VecDeque<ActivityEvent>>>Ring buffer of recent activity (requests, policy denials, fetches) for the dev inspector’s Activity panel. Only written to in dev mode.
Implementations§
Source§impl AppState
impl AppState
Sourcepub fn record_activity(&self, event: ActivityEvent)
pub fn record_activity(&self, event: ActivityEvent)
Record an event in the inspector activity feed. No-op outside dev mode, so production requests never touch the lock.
Source§impl AppState
impl AppState
pub fn new(config: Config, root: PathBuf) -> Result<Self>
Sourcepub fn with_dev_mode(
config: Config,
root: PathBuf,
dev_mode: bool,
) -> Result<Self>
pub fn with_dev_mode( config: Config, root: PathBuf, dev_mode: bool, ) -> Result<Self>
Create AppState with development mode enabled (includes live reload)
Sourcepub async fn init_datasources(&self) -> Result<()>
pub async fn init_datasources(&self) -> Result<()>
Run async initialization for datasources that need it (e.g., D1 system tables). Call this after construction from an async context. Fails if any D1 init fails.
Sourcepub fn trigger_reload(&self)
pub fn trigger_reload(&self)
Trigger a live reload notification (clears cache and notifies clients)
Sourcepub async fn trigger_reload_async(&self)
pub async fn trigger_reload_async(&self)
Trigger live reload — clears cache first, then notifies clients Use this from async contexts to guarantee cache is cleared before reload
Sourcepub fn live_reload_receiver(&self) -> Option<Receiver<LiveReloadMessage>>
pub fn live_reload_receiver(&self) -> Option<Receiver<LiveReloadMessage>>
Get a receiver for live reload messages
Sourcepub async fn rebuild_wired_scopes(&self)
pub async fn rebuild_wired_scopes(&self)
Rebuild the wired + app scope registries by scanning all
application.what files. Wired scopes filter WebSocket delivery; app
scopes gate who may write app.* keys via w-set.
Sourcepub async fn get_wired_scope(&self, key: &str) -> WiredScope
pub async fn get_wired_scope(&self, key: &str) -> WiredScope
Look up the scope for a wired key from the registry (defaults to Public)
Sourcepub async fn get_app_scope(&self, key: &str) -> WiredScope
pub async fn get_app_scope(&self, key: &str) -> WiredScope
Look up the write-gate scope for an app.* key (defaults to Public).
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for AppState
impl !UnwindSafe for AppState
impl Freeze for AppState
impl Send for AppState
impl Sync for AppState
impl Unpin for AppState
impl UnsafeUnpin for AppState
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more