lexa_env/
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
11use std::fmt::Debug;
12use std::path;
13
14// --------- //
15// Interface //
16// --------- //
17
18pub trait EnvInterface:
19	serde::de::DeserializeOwned + Debug + Clone + Send + Sync
20{
21	type Settings;
22
23	// NOTE(phisyx): ici typiquement pouvoir définir la fonction en "MaybeAsync"
24	//               aurait été vraiment sympa. Par exemple dans le cas où l'on
25	//               voudrait récupérer les variables d'environnement depuis un
26	//               serveur distant, et non pas depuis les fichiers systèmes.
27	//
28	// https://blog.rust-lang.org/inside-rust/2022/07/27/keyword-generics.html
29	//                              Result<Self, impl std::error::Error>
30	fn setup(_: &Self::Settings) -> Result<Self, super::Error>
31	where
32		Self: Sized;
33
34	/// Récupère les variables d'environnement à partir du contenu d'un fichier
35	/// et retourne une structure avec les données du contenu du fichier en
36	/// guise de valeurs pour chaque champ.
37	fn from_file(path: impl AsRef<path::Path>) -> Result<Self, super::Error> {
38		super::from_file(path)
39	}
40}