Skip to main content

AppState

Struct AppState 

Source
pub struct AppState {
Show 25 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>>>,
}
Expand description

Application state shared across handlers

Fields§

§config: Arc<Config>

Configuration

§store: DatabaseAdapter

Data store (SQLite, D1, or Supabase — configured via [database] in what.toml)

§cache: WhatCache

Cache

§components: Arc<ComponentRegistry>

Component registry

§engine: Arc<RenderEngine>

Render engine

§root: PathBuf

Project root directory

§content_dir: PathBuf

Resolved content directory path (root + “site” or “pages”)

§sessions: Option<SessionBackend>

Session store (pluggable: SQLite or Cloudflare KV)

§auth: AuthHandler

Authentication handler

§dev_mode: bool

Development mode flag

§css_mode: CssMode

Framework 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: String

Log level string for debug meta injection (dev mode only)

§jobs: JobQueue

Background job queue for async operations (session cleanup, email, etc.)

§http_client: Client

Shared 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.

Implementations§

Source§

impl AppState

Source

pub fn new(config: Config, root: PathBuf) -> Result<Self>

Source

pub fn with_dev_mode( config: Config, root: PathBuf, dev_mode: bool, ) -> Result<Self>

Create AppState with development mode enabled (includes live reload)

Source

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.

Source

pub fn trigger_reload(&self)

Trigger a live reload notification (clears cache and notifies clients)

Source

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

Source

pub fn live_reload_receiver(&self) -> Option<Receiver<LiveReloadMessage>>

Get a receiver for live reload messages

Source

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.

Source

pub async fn get_wired_scope(&self, key: &str) -> WiredScope

Look up the scope for a wired key from the registry (defaults to Public)

Source

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§

Source§

impl Clone for AppState

Source§

fn clone(&self) -> AppState

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Chain<T> for T

Source§

fn len(&self) -> usize

The number of items that this chain link consists of.
Source§

fn append_to(self, v: &mut Vec<T>)

Append the elements in this link to the chain.
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Container<T> for T
where T: Clone,

Source§

type Iter = Once<T>

An iterator over the items within this container, by value.
Source§

fn get_iter(&self) -> <T as Container<T>>::Iter

Iterate over the elements of the container (using internal iteration because GATs are unstable).
Source§

impl<F, W, T, D> Deserialize<With<T, W>, D> for F
where W: DeserializeWith<F, T, D>, D: Fallible + ?Sized, F: ?Sized,

Source§

fn deserialize( &self, deserializer: &mut D, ) -> Result<With<T, W>, <D as Fallible>::Error>

Deserializes using the given deserializer
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> OrderedContainer<T> for T
where T: Clone,

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The type for metadata in pointers and references to Self.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more