Skip to main content

Application

Struct Application 

Source
pub struct Application { /* private fields */ }

Implementations§

Source§

impl Application

Source

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.

Source

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().

Source

pub fn router(self, router: Router) -> Self

Sets the router that will handle incoming requests.

Source

pub fn config(&self) -> &Config

Source

pub fn state(&self) -> AppState

Explicit application state suitable for application-owned Axum state.

Source

pub fn paths(&self) -> &AppPaths

Source

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.

Source

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.

Source

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.

Source

pub async fn serve(self) -> Result<(), AppError>

Binds to config.app_port on localhost and serves until the process is terminated.

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> 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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