zino-core 0.46.2

Core types and traits for zino.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use crate::error::Error;
use std::path::Path;
use toml::value::Table;

/// Reads the config from a local file.
pub(super) fn read_config_file(config_file: &Path, env: &str) -> Result<Table, Error> {
    let data = std::fs::read_to_string(config_file)?;
    let config_table = if config_file.extension().and_then(|s| s.to_str()) == Some("json") {
        serde_json::from_str(&data)?
    } else {
        data.parse()?
    };
    if let Some(file_name) = config_file.file_name().and_then(|s| s.to_str()) {
        tracing::info!(env, "load the config `{file_name}`");
    }
    Ok(config_table)
}