From ff3b9fbaf400c344cae67ef9bdc9ba7d5f27b976 Mon Sep 17 00:00:00 2001 From: rtkay123 Date: Sun, 29 Mar 2026 16:36:13 +0200 Subject: refactor: move state to core --- lib/warden-core/src/state/mod.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 lib/warden-core/src/state/mod.rs (limited to 'lib/warden-core/src/state/mod.rs') diff --git a/lib/warden-core/src/state/mod.rs b/lib/warden-core/src/state/mod.rs new file mode 100644 index 0000000..f4692c2 --- /dev/null +++ b/lib/warden-core/src/state/mod.rs @@ -0,0 +1,24 @@ +pub(crate) mod database; +use sqlx::PgPool; +use tracing_subscriber::EnvFilter; + +use crate::{WardenError, config::Configuration}; + +pub type LogHandle = tracing_subscriber::reload::Handle; + +#[derive(Debug, Clone)] +pub struct AppState { + pub log_handle: LogHandle, + pub database: PgPool, +} + +impl AppState { + pub async fn new(log_handle: LogHandle, config: &Configuration) -> Result { + let database = database::connect(&config.database).await?; + + Ok(Self { + log_handle, + database, + }) + } +} -- cgit v1.2.3