#[non_exhaustive]pub struct AppState { /* private fields */ }Expand description
Shared application state passed to all route handlers.
Holds framework-managed resources such as the database connection pool.
Axum requires handler state to be Clone, so internal resources use
Arc or are already cheaply cloneable (deadpool::Pool is Arc-wrapped
internally).
This struct is normally constructed by crate::app::AppBuilder::run and
should not need to be created manually. It is public so that custom
Axum extractors can access framework resources via
State<AppState>.
§Examples
use autumn_web::AppState;
// State without a database (e.g., for testing)
let state = AppState::for_test().with_profile("dev");Implementations§
Source§impl AppState
impl AppState
Sourcepub fn insert_extension<T>(&self, value: T)
pub fn insert_extension<T>(&self, value: T)
Install or replace a typed runtime extension.
Integrations use this to publish typed runtime resources, such as background-worker handles or dedicated storage pools, after startup.
§Panics
Panics if the internal extension map mutex is poisoned.
Sourcepub const fn pool(&self) -> Option<&Pool<AsyncPgConnection>>
pub const fn pool(&self) -> Option<&Pool<AsyncPgConnection>>
Returns the database connection pool.
Sourcepub const fn replica_pool(&self) -> Option<&Pool<AsyncPgConnection>>
pub const fn replica_pool(&self) -> Option<&Pool<AsyncPgConnection>>
Returns the read-replica database connection pool, if configured.
Sourcepub fn read_pool(&self) -> Option<&Pool<AsyncPgConnection>>
pub fn read_pool(&self) -> Option<&Pool<AsyncPgConnection>>
Returns the pool used for read-only work.
Sourcepub const fn metrics(&self) -> &MetricsCollector
pub const fn metrics(&self) -> &MetricsCollector
Returns the metrics collector.
Sourcepub const fn log_levels(&self) -> &LogLevels
pub const fn log_levels(&self) -> &LogLevels
Returns the log levels configuration.
Sourcepub const fn task_registry(&self) -> &TaskRegistry
pub const fn task_registry(&self) -> &TaskRegistry
Returns the task registry.
Sourcepub const fn job_registry(&self) -> &JobRegistry
pub const fn job_registry(&self) -> &JobRegistry
Returns the job registry.
Sourcepub const fn config_props(&self) -> &ConfigProperties
pub const fn config_props(&self) -> &ConfigProperties
Returns the config properties.
Sourcepub const fn probes(&self) -> &ProbeState
pub const fn probes(&self) -> &ProbeState
Returns the shared probe lifecycle state.
Sourcepub fn mark_startup_complete(&self)
pub fn mark_startup_complete(&self)
Mark startup as complete so readiness can become healthy.
Sourcepub fn begin_shutdown(&self)
pub fn begin_shutdown(&self)
Mark the application as draining so readiness flips unhealthy.
Sourcepub fn with_pool(self, pool: Pool<AsyncPgConnection>) -> Self
pub fn with_pool(self, pool: Pool<AsyncPgConnection>) -> Self
Sets the database pool.
Sourcepub fn with_replica_pool(self, pool: Pool<AsyncPgConnection>) -> Self
pub fn with_replica_pool(self, pool: Pool<AsyncPgConnection>) -> Self
Sets the read-replica database pool.
Sourcepub fn with_extension<T>(self, value: T) -> Self
pub fn with_extension<T>(self, value: T) -> Self
Install a typed runtime extension while building test or ad-hoc state.
Sourcepub fn cache(&self) -> Option<Arc<dyn Cache>>
pub fn cache(&self) -> Option<Arc<dyn Cache>>
Returns the registered global cache backend, if any.
Checks the extension map first (populated at runtime by startup hooks
via Self::set_cache) so that a plugin replacing a build-time backend
is always visible. Falls back to shared_cache (set at build time via
Self::with_cache).
Sourcepub fn with_cache(self, cache: Arc<dyn Cache>) -> Self
pub fn with_cache(self, cache: Arc<dyn Cache>) -> Self
Register a global cache backend (builder / test helper, build-time).
Sourcepub fn set_cache(&self, cache: Arc<dyn Cache>)
pub fn set_cache(&self, cache: Arc<dyn Cache>)
Install or replace the global cache backend at runtime (e.g. from a startup hook).
Updates both the process-level global (used by #[cached] functions) and
the extension map (used by CacheResponseLayer::from_app and state.cache()).
Sourcepub fn with_profile(self, profile: impl Into<String>) -> Self
pub fn with_profile(self, profile: impl Into<String>) -> Self
Sets the active profile.
Sourcepub const fn policy_registry(&self) -> &PolicyRegistry
pub const fn policy_registry(&self) -> &PolicyRegistry
Returns a reference to the PolicyRegistry.
Sourcepub fn policy<R: Send + Sync + 'static>(&self) -> Option<Arc<dyn Policy<R>>>
pub fn policy<R: Send + Sync + 'static>(&self) -> Option<Arc<dyn Policy<R>>>
Resolve the registered Policy for resource R, if any.
Sourcepub fn scope<R: Send + Sync + 'static>(&self) -> Option<Arc<dyn Scope<R>>>
pub fn scope<R: Send + Sync + 'static>(&self) -> Option<Arc<dyn Scope<R>>>
Resolve the registered Scope for resource R, if any.
Sourcepub const fn forbidden_response(&self) -> ForbiddenResponse
pub const fn forbidden_response(&self) -> ForbiddenResponse
Configured deny-response shape. See
ForbiddenResponse for the trade-off between 403 and
404 defaults.
Sourcepub fn auth_session_key(&self) -> &str
pub fn auth_session_key(&self) -> &str
Session key used to resolve the authenticated user id for
PolicyContext.
Sourcepub fn uptime_display(&self) -> String
pub fn uptime_display(&self) -> String
Format uptime as a human-readable string (e.g., “2h 15m”).
Sourcepub const fn channels(&self) -> &Channels
pub const fn channels(&self) -> &Channels
Returns a reference to the broadcast channel registry.
Shorthand for accessing self.channels directly.
Sourcepub fn broadcast(&self) -> Broadcast
pub fn broadcast(&self) -> Broadcast
Returns a high-level broadcast facade for raw and htmx HTML payloads.
Sourcepub fn shutdown_token(&self) -> CancellationToken
pub fn shutdown_token(&self) -> CancellationToken
Returns a child cancellation token for the server shutdown signal.
WebSocket handlers should select on this to clean up when the server is shutting down.
Trait Implementations§
Source§impl DbState for AppState
Available on crate feature db only.
impl DbState for AppState
db only.Source§fn pool(&self) -> Option<&Pool<AsyncPgConnection>>
fn pool(&self) -> Option<&Pool<AsyncPgConnection>>
Source§fn replica_pool(&self) -> Option<&Pool<AsyncPgConnection>>
fn replica_pool(&self) -> Option<&Pool<AsyncPgConnection>>
Source§impl FromRequest<AppState> for SignedWebhook
impl FromRequest<AppState> for SignedWebhook
Source§impl FromRequestParts<AppState> for AutumnConfig
impl FromRequestParts<AppState> for AutumnConfig
Source§impl FromRequestParts<AppState> for Mailer
impl FromRequestParts<AppState> for Mailer
Source§impl ProvideActuatorState for AppState
impl ProvideActuatorState for AppState
Source§fn metrics(&self) -> &MetricsCollector
fn metrics(&self) -> &MetricsCollector
crate::middleware::MetricsCollector
tracking current HTTP traffic metrics.Source§fn log_levels(&self) -> &LogLevels
fn log_levels(&self) -> &LogLevels
LogLevels configuration
allowing runtime adjustment of tracing filters.Source§fn task_registry(&self) -> &TaskRegistry
fn task_registry(&self) -> &TaskRegistry
TaskRegistry holding status and metadata
for async scheduled background tasks.Source§fn job_registry(&self) -> &JobRegistry
fn job_registry(&self) -> &JobRegistry
JobRegistry holding queue and failure
information for ad-hoc background jobs.Source§fn config_props(&self) -> &ConfigProperties
fn config_props(&self) -> &ConfigProperties
ConfigProperties snapshot, providing
active configuration state for the environment endpoint.Source§fn profile(&self) -> &str
fn profile(&self) -> &str
Source§fn uptime_display(&self) -> String
fn uptime_display(&self) -> String
Source§fn channels(&self) -> &Channels
fn channels(&self) -> &Channels
crate::channels::Channels which
broadcasts operational events to WebSocket streams.Source§fn shutdown_token(&self) -> CancellationToken
fn shutdown_token(&self) -> CancellationToken
Source§fn pool(&self) -> Option<&Pool<AsyncPgConnection>>
fn pool(&self) -> Option<&Pool<AsyncPgConnection>>
/actuator/metrics endpoint.Source§fn a11y_posture(&self) -> A11yPosture
fn a11y_posture(&self) -> A11yPosture
/actuator/a11y. Read moreSource§impl ProvideProbeState for AppState
impl ProvideProbeState for AppState
Source§fn probes(&self) -> &ProbeState
fn probes(&self) -> &ProbeState
ProbeState that tracks
lifecycle phases (startup, ready, draining).Source§fn health_detailed(&self) -> bool
fn health_detailed(&self) -> bool
Source§fn profile(&self) -> &str
fn profile(&self) -> &str
Source§fn uptime_display(&self) -> String
fn uptime_display(&self) -> String
Source§fn pool(&self) -> Option<&Pool<AsyncPgConnection>>
fn pool(&self) -> Option<&Pool<AsyncPgConnection>>
Source§fn replica_pool(&self) -> Option<&Pool<AsyncPgConnection>>
fn replica_pool(&self) -> Option<&Pool<AsyncPgConnection>>
Source§fn mark_startup_complete(&self)
fn mark_startup_complete(&self)
Auto Trait Implementations§
impl Freeze for AppState
impl !RefUnwindSafe for AppState
impl Send for AppState
impl Sync for AppState
impl Unpin for AppState
impl UnsafeUnpin for AppState
impl !UnwindSafe for AppState
Blanket Implementations§
Source§impl<T> AggregateExpressionMethods for T
impl<T> AggregateExpressionMethods for T
Source§fn aggregate_distinct(self) -> Self::Outputwhere
Self: DistinctDsl,
fn aggregate_distinct(self) -> Self::Outputwhere
Self: DistinctDsl,
DISTINCT modifier for aggregate functions Read moreSource§fn aggregate_all(self) -> Self::Outputwhere
Self: AllDsl,
fn aggregate_all(self) -> Self::Outputwhere
Self: AllDsl,
ALL modifier for aggregate functions Read moreSource§fn aggregate_filter<P>(self, f: P) -> Self::Output
fn aggregate_filter<P>(self, f: P) -> Self::Output
Source§fn aggregate_order<O>(self, o: O) -> Self::Outputwhere
Self: OrderAggregateDsl<O>,
fn aggregate_order<O>(self, o: O) -> Self::Outputwhere
Self: OrderAggregateDsl<O>,
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<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
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> IntoSql for T
impl<T> IntoSql for T
Source§fn into_sql<T>(self) -> Self::Expression
fn into_sql<T>(self) -> Self::Expression
self to an expression for Diesel’s query builder. Read moreSource§fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
&self to an expression for Diesel’s query builder. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> RepositoryHooksClone for Twhere
T: Clone,
impl<T> RepositoryHooksClone for Twhere
T: Clone,
Source§fn autumn_clone(&self) -> T
fn autumn_clone(&self) -> T
Source§impl<T, Conn> RunQueryDsl<Conn> for T
impl<T, Conn> RunQueryDsl<Conn> for T
Source§fn execute<'conn, 'query>(
self,
conn: &'conn mut Conn,
) -> <Conn as AsyncConnectionCore>::ExecuteFuture<'conn, 'query>
fn execute<'conn, 'query>( self, conn: &'conn mut Conn, ) -> <Conn as AsyncConnectionCore>::ExecuteFuture<'conn, 'query>
Source§fn load<'query, 'conn, U>(
self,
conn: &'conn mut Conn,
) -> AndThen<Self::LoadFuture<'conn>, TryCollect<Self::Stream<'conn>, Vec<U>>>
fn load<'query, 'conn, U>( self, conn: &'conn mut Conn, ) -> AndThen<Self::LoadFuture<'conn>, TryCollect<Self::Stream<'conn>, Vec<U>>>
Source§fn load_stream<'conn, 'query, U>(
self,
conn: &'conn mut Conn,
) -> Self::LoadFuture<'conn>where
Conn: AsyncConnectionCore,
U: 'conn,
Self: LoadQuery<'query, Conn, U> + 'query,
fn load_stream<'conn, 'query, U>(
self,
conn: &'conn mut Conn,
) -> Self::LoadFuture<'conn>where
Conn: AsyncConnectionCore,
U: 'conn,
Self: LoadQuery<'query, Conn, U> + 'query,
Stream] with the returned rows. Read moreSource§fn get_result<'query, 'conn, U>(
self,
conn: &'conn mut Conn,
) -> AndThen<Self::LoadFuture<'conn>, LoadNext<Pin<Box<Self::Stream<'conn>>>>>
fn get_result<'query, 'conn, U>( self, conn: &'conn mut Conn, ) -> AndThen<Self::LoadFuture<'conn>, LoadNext<Pin<Box<Self::Stream<'conn>>>>>
Source§fn get_results<'query, 'conn, U>(
self,
conn: &'conn mut Conn,
) -> AndThen<Self::LoadFuture<'conn>, TryCollect<Self::Stream<'conn>, Vec<U>>>
fn get_results<'query, 'conn, U>( self, conn: &'conn mut Conn, ) -> AndThen<Self::LoadFuture<'conn>, TryCollect<Self::Stream<'conn>, Vec<U>>>
Vec with the affected rows. Read moreSource§impl<T> Scoped for T
impl<T> Scoped for T
Source§fn scope(ctx: &PolicyContext) -> ScopeQuery<'_, Self>
fn scope(ctx: &PolicyContext) -> ScopeQuery<'_, Self>
ScopeQuery for this type. Resolves the
registered scope at .load() time, not here.