#[state]Expand description
Generates application state with entity collections.
§Syntax
ⓘ
#[stately::state]
pub struct AppState {
// Regular collections (many entities)
pipelines: Pipeline,
sources: SourceConfig,
// Singletons (one entity)
#[singleton]
parse_settings: BufferSettings,
}§API Generation
Optionally generate web API code by specifying the api attribute:
ⓘ
#[stately::state(api = ["axum"])]
pub struct AppState {
pipelines: Pipeline,
}This generates a namespaced module (e.g., axum_api) with:
- Concrete response types with OpenAPI schemas
- Handler functions with OpenAPI path annotations
- A router function
- An OpenAPI documentation struct
§Generated Code
This generates:
StateEntryenum with variants for each entity typeEntityenum wrapping each entity for type erasure- The state struct with collection fields
- CRUD operation methods
- (Optional) API-specific modules for web frameworks