hermes_cli_components/impls/config/
load_toml_config.rs1use cgp::core::error::CanRaiseError;
2use hermes_runtime_components::traits::fs::read_file::CanReadFileAsString;
3use hermes_runtime_components::traits::runtime::HasRuntime;
4use serde::de::DeserializeOwned;
5
6use crate::traits::config::config_path::HasConfigPath;
7use crate::traits::config::load_config::ConfigLoader;
8use crate::traits::types::config::HasConfigType;
9
10pub struct LoadTomlConfig;
11
12impl<App, Runtime, Config> ConfigLoader<App> for LoadTomlConfig
13where
14 App: HasRuntime<Runtime = Runtime>
15 + HasConfigType<Config = Config>
16 + HasConfigPath
17 + CanRaiseError<Runtime::Error>
18 + CanRaiseError<toml::de::Error>,
19 Runtime: CanReadFileAsString,
20 Config: DeserializeOwned,
21{
22 async fn load_config(app: &App) -> Result<App::Config, App::Error> {
23 let config_path = app.config_path();
24
25 let config_str = app
26 .runtime()
27 .read_file_as_string(config_path)
28 .await
29 .map_err(App::raise_error)?;
30
31 let config = toml::from_str(&config_str).map_err(App::raise_error)?;
32
33 Ok(config)
34 }
35}