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
// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
// ┃ 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/. ┃
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
use std::path;
use super::Error;
// --------- //
// Interface //
// --------- //
pub trait ApplicationEnvInterface:
std::fmt::Debug + Clone + Send + Sync
{
// NOTE(phisyx): ici typiquement un maybe async aurait été vraiment
// sympa.
// Dans le cas où l'on voudrait récupérer les variables d'environnement
// depuis une URL distant.
/* #[async] */
fn setup(_: &crate::application::Settings) -> Result<Self, Error>
where
Self: Sized;
/// Récupère les variables d'environnement à partir du contenu d'un fichier
/// et retourne une structure avec les données du contenu du fichier en
/// guise de valeurs pour chaque champ.
fn fetch_from_file<T>(
env_filepath: impl AsRef<path::Path>,
) -> Result<T, Error>
where
T: serde::de::DeserializeOwned,
{
Ok(lexa_env::from_file(env_filepath)?)
}
}
// -------------- //
// Implémentation // -> Interface
// -------------- //
impl ApplicationEnvInterface for () {
fn setup(_: &crate::application::Settings) -> Result<Self, Error>
where
Self: Sized,
{
Ok(())
}
}