serfig 0.1.0

Layered configuration system built upon serde
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use anyhow::{anyhow, Result};
use serde::de::DeserializeOwned;

use crate::Parser;

/// Toml format support
#[derive(Debug)]
pub struct Toml;

impl Parser for Toml {
    fn parse<T: DeserializeOwned>(&mut self, bs: &[u8]) -> Result<T> {
        let s = std::str::from_utf8(bs)
            .map_err(|err| anyhow!("input value is not valid utf-8: {err:?}"))?;
        Ok(toml::from_str(s)?)
    }
}