mod interface;
pub use self::interface::StateInterface;
#[derive(Clone)]
pub struct State<UserState> {
#[cfg(feature = "cookies")]
pub cookie_key: Option<tower_cookies::Key>,
#[cfg(feature = "database-postgres")]
pub database_postgres:
Option<crate::database::services::postgres::PostgresService>,
pub user_state: Option<UserState>,
}
#[cfg(feature = "cookies")]
impl<US> axum::extract::FromRef<State<US>> for tower_cookies::Key {
fn from_ref(state: &State<US>) -> Self {
state.cookie_key.clone().expect(
"Veuillez définir une clé de cookie dans votre application. \
`your_app.server.define_encrypt_key(&key)`.",
)
}
}
#[cfg(feature = "database-postgres")]
impl<US> axum::extract::FromRef<State<US>>
for crate::database::services::postgres::PostgresService
{
fn from_ref(state: &State<US>) -> Self {
state.database_postgres.clone().expect(
"Veuillez définir la connexion à la base de données dans votre \
application. Utilisez: \
`your_app.server.using_database_postgres_service(&database_url)`.",
)
}
}
impl axum::extract::FromRef<State<()>> for () {
fn from_ref(_: &State<()>) -> Self {}
}