fun-folder-common 0.1.1

Common package used by `fun-folder` project ecosystem
Documentation
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); // Any content in file under given folder. Will raise on subfolders if configured as recursive.
    fn on_delete(&self, path: &PathBuf);
    fn on_rename(&self, path: &PathBuf);
}

pub struct FolderHandler{
    pid: Option<u32> // Process id of live handler.
}

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)
    }
}