hippo_shared/
configuration.rs1use std::collections::HashMap;
7use std::env;
8use std::fs;
9use std::io::{Error, ErrorKind, Result};
10use std::path::{Path, PathBuf};
11
12use serde::Deserialize;
13
14use super::Preprocessor;
15
16#[derive(Deserialize)]
18pub struct Configuration {
19 #[serde(flatten)]
20 pub preprocessors: HashMap<String, Preprocessor>
21}
22
23impl Configuration {
24 pub const DEFAULT_NAME: &'static str = "Hippo.toml";
26
27 pub fn locate() -> Option<PathBuf> {
29 env::var("CARGO_MANIFEST_DIR").ok().map(|p| {
30 let mut buf = PathBuf::new();
31
32 buf.push(p);
33 buf.push(Self::DEFAULT_NAME);
34
35 buf
36 })
37 }
38
39 pub fn load(path: &Path) -> Result<Self> {
41 toml::from_str(&fs::read_to_string(path)?).map_err(
42 |e| Error::new(ErrorKind::Other, e)
43 )
44 }
45}