Files
own_assist/common/src/config_loader.rs
T
2026-05-03 18:28:20 +02:00

19 lines
485 B
Rust

use serde::de::DeserializeOwned;
use std::path::Path;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum ConfigLoadingError {
#[error(transparent)]
IoError(#[from] std::io::Error),
#[error(transparent)]
ParseError(#[from] toml::de::Error),
}
pub fn config_from_file<T: DeserializeOwned>(
filepath: impl AsRef<Path>,
) -> Result<T, ConfigLoadingError> {
let toml_string: String = std::fs::read_to_string(filepath)?;
Ok(toml::from_str(&toml_string)?)
}