Crates.io | quadoculars |
lib.rs | quadoculars |
version | 0.1.40 |
source | src |
created_at | 2021-03-04 01:48:51.360544 |
updated_at | 2021-03-25 16:08:03.68592 |
description | Concurrent, composable simple file watcher on top of notify-rs with fast live reloading support. |
homepage | |
repository | https://github.com/Ar37-rs/quadoculars |
max_upload_size | |
id | 363505 |
size | 35,346 |
Concurrent, composable simple file watcher on top of notify-rs.
Add quadoculars
as a dependency in your Cargo.toml
:
quadoculars = "*"
or
quadoculars = { git = "https://github.com/Ar37-rs/quadoculars.git" }
use quadoculars::{Fstate, Watch};
use std::{
io::Result,
path::{Path, PathBuf},
str::FromStr,
sync::mpsc::channel,
};
fn main() -> Result<()> {
let file: PathBuf;
{
match PathBuf::from_str("filename.extention") {
Ok(file_) => file = file_,
_ => file = Path::new("otherfilename.otherextension").to_path_buf(),
}
}
let (tx, rx) = channel();
while let Ok(file_exist) = Watch::new().set_timeout(0.6).single_file(&file,tx.clone()) {
if !file_exist {
println!("no file to watch");
break;
} else {
println!("watching... {:?}", file)
}
for state in &rx {
match state {
Fstate::Changed(file) => {
println!("{:?} changed", file);
// do something...
}
Fstate::NotFound(file) => {
// handle something...
break;
}
}
}
}
Ok(())
}
Watching Multiple files and live reloading values can be found here.