1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use std::fmt;
use std::path::PathBuf;
use std::process::Command;
pub trait FolderEventHandler{
fn on_create(&self, path: &PathBuf);
fn on_modify(&self, path: &PathBuf);
fn on_delete(&self, path: &PathBuf);
fn on_rename(&self, path: &PathBuf);
}
pub struct FolderHandler{
pid: Option<u32>
}
impl FolderHandler {
pub fn new(program_path: &str) -> Self {
let mut command = Command::new(program_path);
if let Ok(child) = command.spawn() {
Self{pid: Some(child.id())}
} else {
Self{pid: None}
}
}
}
impl fmt::Display for FolderHandler{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(f, "PID: {:?}", self.pid)
}
}