add some basic config file parsing
This commit is contained in:
parent
9816809143
commit
9a8896e855
5 changed files with 1594 additions and 13 deletions
34
src/monitor.rs
Normal file
34
src/monitor.rs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
use serde::Deserialize;
|
||||
use std::fs;
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum Error {
|
||||
#[error("io error")]
|
||||
IoError(#[from] std::io::Error),
|
||||
#[error("toml parsing error")]
|
||||
ParseError(#[from] toml::de::Error),
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct MonitorConfig {
|
||||
target: Vec<String>,
|
||||
}
|
||||
impl MonitorConfig {
|
||||
fn print(&self) {
|
||||
for t in &self.target {
|
||||
println!("* {}", t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Monitor {}
|
||||
|
||||
impl Monitor {
|
||||
pub fn new_from_file(config_file: &str) -> Result<Self, Error> {
|
||||
let config_str = fs::read_to_string(config_file)?;
|
||||
let config: MonitorConfig = toml::from_str(&config_str)?;
|
||||
config.print();
|
||||
Ok(Self {})
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue