use crate::app_error::AppError;
use config::Config;
use config::File;
use config::FileFormat;
use serde::de::DeserializeOwned;
use std::path::Path;
pub mod custom;
pub mod raw;
pub mod config_file;
pub mod config_theme;
pub mod config_type;
pub fn deserialize_to_config<R>(file_path: &Path) -> Result<R, AppError<()>>
where
R: DeserializeOwned,
{
let builder: R = Config::builder()
.add_source(File::from(file_path).format(FileFormat::Toml))
.build()?
.try_deserialize::<R>()?;
Ok(builder)
}
pub fn deserialize_to_config_into<R, S>(file_path: &Path) -> Result<S, AppError<()>>
where
R: DeserializeOwned + Into<S>,
{
deserialize_to_config::<R>(file_path).map(|s| s.into())
}