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