libmeld/
config.rs

1use log::info;
2use std::collections::HashMap;
3
4use crate::hash_contents;
5use crate::hash_path;
6use crate::Config;
7use crate::Error;
8
9impl Config {
10    // Getters
11    pub fn get_blob(&self) -> &String {
12        &self.blob
13    }
14
15    pub fn get_real_path(&self) -> &String {
16        &self.real_path
17    }
18
19    pub fn get_tag(&self) -> &String {
20        &self.tag
21    }
22
23    pub fn get_hash(&self) -> &String {
24        &self.hash
25    }
26
27    /// Create a Config from a path and arguments
28    pub fn from(
29        real_path: String,
30        map_path: String,
31        subset: String,
32        family: String,
33        tag: String,
34    ) -> Result<Self, Error> {
35        info!("Using config at {}", &real_path);
36        info!("Config mapped to {}", map_path);
37
38        let config = Config {
39            blob: hash_path(&map_path),
40            subset,
41            family,
42            map_path,
43            hash: hash_contents(&real_path)?,
44            real_path,
45            tag,
46            versions: HashMap::new(),
47        };
48
49        return Ok(config);
50    }
51}