pub struct Application { /* private fields */ }Implementations§
Source§impl Application
impl Application
Sourcepub fn new(config: fn() -> Value) -> Result<Self, AppError>
pub fn new(config: fn() -> Value) -> Result<Self, AppError>
Loads config, initializes logging, flips the process-wide debug flag
(crate::debug) that gates descriptive error pages, and publishes
config process-wide (crate::config::config(), used by
larust_support::url()/asset()/config()).
config is the app’s own generated config/app.rs’s pub fn config() -> serde_json::Value (e.g. my_app::config::app::config) -
a plain function item, not a closure, so every real caller can
just pass the function itself. Called after .env is loaded (see
with_paths below), so its own env/env_bool/env_or calls
(larust_support::config_env) see whatever .env set.
This does a small amount of synchronous filesystem I/O (loading
.env) even when called from inside an async runtime. That’s
intentional: it runs once at startup, before any other async work is
scheduled, so the blocking cost is negligible - not worth the
complexity of spawn_blocking for a few KB of env file.
Sourcepub fn at_root(
root: impl Into<PathBuf>,
config: fn() -> Value,
) -> Result<Self, AppError>
pub fn at_root( root: impl Into<PathBuf>, config: fn() -> Value, ) -> Result<Self, AppError>
Creates an application rooted at root, independent of the process
working directory. New binaries should prefer this over new().
Sourcepub fn router(self, router: Router) -> Self
pub fn router(self, router: Router) -> Self
Sets the router that will handle incoming requests.
pub fn config(&self) -> &Config
Sourcepub fn state(&self) -> AppState
pub fn state(&self) -> AppState
Explicit application state suitable for application-owned Axum state.
pub fn paths(&self) -> &AppPaths
Sourcepub fn with_graceful_shutdown(self, config: GracefulShutdown) -> Self
pub fn with_graceful_shutdown(self, config: GracefulShutdown) -> Self
Opts into graceful shutdown: on Ctrl+C (or, on Unix, SIGTERM),
serve() stops accepting new connections and waits for in-flight
ones to finish (bounded by config.drain_timeout) before exiting,
instead of exiting instantly. See GracefulShutdown’s own doc
comment for why this is opt-in rather than the default.
Sourcepub fn with_health_route(self, path: impl Into<String>) -> Self
pub fn with_health_route(self, path: impl Into<String>) -> Self
Registers Laravel-style health routing. Laravel applications use
'/up' by default, so generated Larust applications should call
.with_health_route("/up") during bootstrap.
The endpoint is deliberately opt-in so applications keep control of
their route namespace. It returns 200 OK once Larust has completed
bootstrap; a future diagnostic registry can add dependency checks
without changing the route contract.
Sourcepub fn with_error_pages(self, pages: ErrorPages) -> Self
pub fn with_error_pages(self, pages: ErrorPages) -> Self
Registers the app’s 404/500 pages, rendered once here (not per
request - see ErrorPages’ own doc comment) and used by every
AppError::NotFound/Internal/Config/caught-panic response for
the rest of the process’s life. Entirely optional - AppError’s own
into_response() falls back to Larust’s built-in default pages if
this is never called, so an app that skips this still gets styled
error pages, just not the option to override them.