1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use crate::package::Package;
use serde_derive::Deserialize;
use std::collections::BTreeMap;
use std::path::Path;
use thiserror::Error;
#[derive(Deserialize, Debug)]
pub struct Config {
#[serde(default, rename = "package")]
pub packages: BTreeMap<String, Package>,
}
#[derive(Error, Debug)]
pub enum ParseError {
#[error("Cannot parse toml: {0}")]
Toml(#[from] toml::de::Error),
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
}
pub fn parse<P: AsRef<Path>>(path: P) -> Result<Config, ParseError> {
let contents = std::fs::read_to_string(path.as_ref())?;
let cfg = toml::from_str::<Config>(&contents)?;
Ok(cfg)
}