lyrs/src/state.rs

28 lines
527 B
Rust
Raw Normal View History

2024-05-17 13:55:16 -05:00
use crate::{
db::{self, Data},
prelude::*,
};
2024-05-17 12:00:37 -05:00
use thiserror::Error;
2024-05-14 12:28:27 -05:00
#[derive(Clone)]
pub struct State {
2024-05-17 13:55:16 -05:00
db: Data,
2024-05-14 12:28:27 -05:00
}
impl State {
2024-05-17 13:55:16 -05:00
pub async fn try_new(
database_connection_string: &str,
database_reset: bool,
) -> Result<Self, NewStateError> {
2024-05-17 12:00:37 -05:00
Ok(Self {
2024-05-17 13:55:16 -05:00
db: Data::try_new(database_connection_string, database_reset).await?,
2024-05-17 12:00:37 -05:00
})
2024-05-14 12:28:27 -05:00
}
}
2024-05-15 16:48:23 -05:00
#[derive(Error, Debug)]
pub enum NewStateError {
2024-05-17 12:00:37 -05:00
#[error("database error: {0}")]
2024-05-17 13:55:16 -05:00
Database(#[from] db::NewDataError),
2024-05-15 16:48:23 -05:00
}