lexa_framework/application/
interface.rs

1// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
2// ┃ Copyright: (c) 2023, Mike 'PhiSyX' S. (https://github.com/PhiSyX)         ┃
3// ┃ SPDX-License-Identifier: MPL-2.0                                          ┃
4// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
5// ┃                                                                           ┃
6// ┃  This Source Code Form is subject to the terms of the Mozilla Public      ┃
7// ┃  License, v. 2.0. If a copy of the MPL was not distributed with this      ┃
8// ┃  file, You can obtain one at https://mozilla.org/MPL/2.0/.                ┃
9// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
10
11mod cli;
12mod env;
13mod logger;
14mod service;
15
16pub use self::cli::ApplicationCLIInterface;
17pub use self::env::ApplicationEnvInterface;
18pub use self::logger::ApplicationLoggerInterface;
19pub use self::service::Service;
20use super::Error;
21use crate::routing;
22
23// --------- //
24// Interface //
25// --------- //
26
27/// Interface d'application web.
28pub trait Application {
29	/// Routeur de l'application.
30	type Router: routing::interface::RouterExt<State = Self::State>;
31
32	/// État utilisateur de l'application.
33	type State;
34
35	fn register_extension(
36		_: &crate::state::State<Self::State>,
37		router: routing::AxumRouter<Self::State>,
38	) -> routing::AxumRouter<Self::State> {
39		router
40	}
41
42	fn register_layer(
43		_: &crate::state::State<Self::State>,
44		router: routing::AxumRouter<Self::State>,
45	) -> routing::AxumRouter<Self::State> {
46		router
47	}
48
49	fn register_middleware(
50		_: &crate::state::State<Self::State>,
51		router: routing::AxumRouter<Self::State>,
52	) -> routing::AxumRouter<Self::State> {
53		router
54	}
55
56	fn register_service(
57		server: crate::server::Server<Self::State>,
58	) -> crate::server::Server<Self::State> {
59		server
60	}
61}
62
63#[async_trait::async_trait]
64pub trait ApplicationCreateExt {
65	type CLI: ApplicationCLIInterface;
66	type ENV: ApplicationEnvInterface;
67
68	/// Définit le mode d'exécution du programme.
69	fn define_process_mode(self, mode: super::env::EnvProcessMode) -> Self
70	where
71		Self: Sized;
72
73	/// Définit les arguments de la CLI, filtrés par les champs de la structure
74	/// implémentant l'interface [CLI_Interface].
75	fn with_cli_args(self) -> Self
76	where
77		Self: Sized;
78
79	/// Définit les variables d'environnement, filtrés par les champs de la
80	/// structure implémentant l'interface [ENV_Interface].
81	fn with_env_vars(self) -> Result<Self, Error>
82	where
83		Self: Sized;
84
85	/// Arguments de la CLI.
86	fn cli_args(&self) -> &Self::CLI;
87
88	/// Variables d'environnement.
89	fn env_vars(&self) -> &Self::ENV;
90}