pf_config 0.1.0

Layered configuration loader (JSON, env, dotenv, Cargo.toml section) with optional WASM-friendly path later
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
use crate::ConfigError;
use serde_json::Value;
use std::path::Path;

pub fn try_load_json_file(path: &Path) -> Result<Option<Value>, ConfigError> {
    if !path.exists() {
        return Ok(None);
    }
    let content = std::fs::read_to_string(path)?;
    if content.trim().is_empty() {
        return Ok(None);
    }
    let v: Value = serde_json::from_str(&content)?;
    Ok(Some(v))
}