fwatch

Crates.iofwatch
lib.rsfwatch
version0.1.5
sourcesrc
created_at2019-07-23 18:19:49.052828
updated_at2019-11-02 09:16:23.848913
descriptionA simple file watching crate
homepage
repositoryhttps://github.com/dcchut/fwatch
max_upload_size
id151113
size24,614
Robert Usher (dcchut)

documentation

README

fwatch

fwatch is a file watching library written in Rust.


Installation

Add this to your Cargo.toml:

[dependencies]
fwatch = "0.1"

Basic Usage

The following example sets up a Watcher to observe any changes (called Transition's in fwatch) to foo.txt and bar.txt. The currently available transitions are Created, Modified, Deleted, and None.

Instead of BasicTarget, any struct implementing the Watchable trait can be used below.

use fwatch::{BasicTarget, Watcher, Transition};

fn main() {
    let mut watcher : Watcher<BasicTarget> = Watcher::new();

    // Add a couple of files to watch
    watcher.add_target(BasicTarget::new("foo.txt"));
    watcher.add_target(BasicTarget::new("bar.txt"));
    
    // Calling watcher.watch() returns a vector of Transitions, 
    // teling us if any of the watched files have undergone a
    // transition since the previous call to watcher.watch()
    for (index, transition) in watcher.watch().into_iter().enumerate() {
        // Get the path and state of the current target
        let path = watcher.get_path(index).unwrap();
        let state = watcher.get_state(index).uwnrap();

        // Do something based on the observed transition.
        match transition {
            Transition::Created => { 
            /* The watched file has been created */ 
            },
            Transition::Modified => { 
            /* The watched file has been modified */ 
            },
            Transition::Deleted => { 
            /* The watched file has been deleted */ 
            },
            Transition::None => { 
            /* None of the above transitions were observed */ 
            },
        }
    }
}

License

Licensed under either of

Commit count: 11

cargo fmt