lexa_framework/application/interface/env.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
11use std::path;
12
13use super::Error;
14
15// --------- //
16// Interface //
17// --------- //
18
19pub trait ApplicationEnvInterface:
20 std::fmt::Debug + Clone + Send + Sync
21{
22 // NOTE(phisyx): ici typiquement un maybe async aurait été vraiment
23 // sympa.
24 // Dans le cas où l'on voudrait récupérer les variables d'environnement
25 // depuis une URL distant.
26 /* #[async] */
27 fn setup(_: &crate::application::Settings) -> Result<Self, Error>
28 where
29 Self: Sized;
30
31 /// Récupère les variables d'environnement à partir du contenu d'un fichier
32 /// et retourne une structure avec les données du contenu du fichier en
33 /// guise de valeurs pour chaque champ.
34 fn fetch_from_file<T>(
35 env_filepath: impl AsRef<path::Path>,
36 ) -> Result<T, Error>
37 where
38 T: serde::de::DeserializeOwned,
39 {
40 Ok(lexa_env::from_file(env_filepath)?)
41 }
42}
43
44// -------------- //
45// Implémentation // -> Interface
46// -------------- //
47
48impl ApplicationEnvInterface for () {
49 fn setup(_: &crate::application::Settings) -> Result<Self, Error>
50 where
51 Self: Sized,
52 {
53 Ok(())
54 }
55}