pd-rs-common 0.2.2

Rust common lib
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//! 加载配置模块

use anyhow::{Result, anyhow};
use serde::de::DeserializeOwned;

pub trait LoadConfig: Sized + DeserializeOwned {
    fn load_toml(path: &str) -> Result<Self>;
}

impl<T: Sized + DeserializeOwned> LoadConfig for T {
    fn load_toml(path: &str) -> Result<Self> {
        let content = std::fs::read_to_string(path)?;
        toml::from_str(content.as_str()).map_err(|e| anyhow!(e))
    }
}