Skip to main content

sword_core/
application.rs

1use serde::{Deserialize, Serialize};
2
3use crate::LayerStack;
4use crate::{Config, ConfigItem, ConfigRegistrar, ControllerRegistry, State, inventory_submit};
5
6/// Configuration structure for the Sword application.
7///
8/// This struct contains only global application configuration.
9///
10/// Engine-specific settings live in their own sections such as `[web]`, `[grpc]`,
11/// and `[socketio]`.
12#[derive(Debug, Clone, Default, Serialize, Deserialize)]
13#[serde(default)]
14pub struct ApplicationConfig {
15    /// Optional name of the application. Defaults `None`.
16    /// This can be used for logging or display purposes.
17    pub name: Option<String>,
18
19    /// Optional environment name (e.g., "development", "production").
20    /// This can be used to alter behavior based on the environment. Defaults `None`.
21    pub environment: Option<String>,
22
23    /// Whether to enable graceful shutdown of the server.
24    /// If true, the server will finish processing ongoing requests
25    /// before shutting down when a termination signal is received.
26    /// Defaults `false`
27    #[serde(rename = "graceful-shutdown")]
28    pub graceful_shutdown: bool,
29}
30
31impl ConfigItem for ApplicationConfig {
32    fn key() -> &'static str {
33        "application"
34    }
35}
36
37inventory_submit! {[
38    ConfigRegistrar::new(|state, config| {
39        state.insert(config.get_or_default::<ApplicationConfig>());
40    })
41]}
42
43/// Context passed from 'ApplicationBuilder' to engine-specific builders.
44///
45/// Contains all shared state accumulated during the builder phase,
46/// after DI resolution and interceptor registration.
47pub struct EngineBuildContext {
48    pub state: State,
49    pub config: Config,
50    pub controllers: ControllerRegistry,
51    pub layer_stack: LayerStack<State>,
52}