lexa_framework/state/
mod.rs1mod interface;
12
13pub use self::interface::StateInterface;
14
15#[derive(Clone)]
21pub struct State<UserState> {
22 #[cfg(feature = "cookies")]
23 pub cookie_key: Option<tower_cookies::Key>,
24 #[cfg(feature = "database-postgres")]
25 pub database_postgres:
26 Option<crate::database::services::postgres::PostgresService>,
27 pub user_state: Option<UserState>,
29}
30
31#[cfg(feature = "cookies")]
36impl<US> axum::extract::FromRef<State<US>> for tower_cookies::Key {
37 fn from_ref(state: &State<US>) -> Self {
38 state.cookie_key.clone().expect(
39 "Veuillez définir une clé de cookie dans votre application. \
40 `your_app.server.define_encrypt_key(&key)`.",
41 )
42 }
43}
44
45#[cfg(feature = "database-postgres")]
46impl<US> axum::extract::FromRef<State<US>>
47 for crate::database::services::postgres::PostgresService
48{
49 fn from_ref(state: &State<US>) -> Self {
50 state.database_postgres.clone().expect(
51 "Veuillez définir la connexion à la base de données dans votre \
52 application. Utilisez: \
53 `your_app.server.using_database_postgres_service(&database_url)`.",
54 )
55 }
56}
57
58impl axum::extract::FromRef<State<()>> for () {
59 fn from_ref(_: &State<()>) -> Self {}
60}