lexa_framework/application/settings.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 logger;
12
13use std::{fmt, path};
14
15pub use self::logger::LoggerSettings;
16
17// --------- //
18// Structure //
19// --------- //
20
21#[derive(Debug)]
22#[derive(Clone)]
23pub struct Settings {
24 /// Répertoire racine de l'application utilisateur.
25 pub root_dir: path::PathBuf,
26
27 /// Répertoire des fichiers de configurations. Peut être un chemin absolu
28 /// ou un chemin relatif à partir de la racine.
29 pub config_dir: path::PathBuf,
30
31 /// Extension à utiliser lors de la récupération de la dé-sérialisation des
32 /// fichiers de configurations.
33 pub loader_extension: SettingsLoaderExtension,
34
35 /// Mode d'execution.
36 pub process_env_mode: super::env::EnvProcessMode,
37}
38
39// ----------- //
40// Énumération //
41// ----------- //
42
43/// Les extensions des fichiers de configurations supportées.
44#[derive(Debug)]
45#[derive(Copy, Clone)]
46#[derive(PartialEq, Eq)]
47pub enum SettingsLoaderExtension {
48 JSON,
49 TOML,
50 YAML,
51}
52
53// -------------- //
54// Implémentation // -> Interface
55// -------------- //
56
57impl fmt::Display for SettingsLoaderExtension {
58 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
59 let ext = match self {
60 | SettingsLoaderExtension::JSON => "json",
61 | SettingsLoaderExtension::TOML => "toml",
62 | SettingsLoaderExtension::YAML => "yml",
63 };
64
65 write!(f, "{}", ext)
66 }
67}