daemon_ctrl/
control.rs

1use serde::{Deserialize, Serialize};
2use std::fs;
3
4#[derive(Debug, Serialize, Deserialize)]
5pub struct Control {
6    pub reboot: bool,
7}
8
9impl Control {
10    pub fn read(file: &str) -> Self {
11        if let Ok(ctrl) = fs::read(file) {
12            if let Ok(ctrl) = serde_json::from_slice(&ctrl) {
13                return ctrl;
14            }
15        }
16        Self { reboot: false }
17    }
18    pub fn save(&self, file: &str) {
19        let ctrl = serde_json::to_string(self).unwrap();
20        fs::write(file, ctrl).unwrap();
21    }
22}