jvmti/
config.rs

1extern crate toml;
2
3use std::fs::File;
4use std::io::{ Read };
5use std::path::Path;
6
7#[derive(Deserialize)]
8pub struct Config {
9    pub agent_name: String,
10    pub entry_points: Vec<String>,
11    pub active_classes: Vec<String>
12}
13
14impl Config {
15
16    pub fn read_config() -> Option<Config> {
17        let default_config: String = String::from("agent.conf");
18
19        Config::read_from_file(default_config)
20    }
21
22    pub fn read_from_file<T: AsRef<Path>>(file_name: T) -> Option<Config> {
23        match File::open(file_name) {
24            Ok(mut file) => {
25                let mut contents = String::new();
26                let _ = file.read_to_string(&mut contents);
27
28                let config: Config = toml::from_str(contents.as_str()).unwrap();
29
30                Some(config)
31            },
32            _ => None
33        }
34    }
35}
36
37impl Default for Config {
38
39    fn default() -> Self {
40        Config {
41            agent_name: String::from("default"),
42            entry_points: vec![],
43            active_classes: vec![]
44        }
45    }
46}