pub fn watch(path: &Path) -> Result<Watch, WatchError>Expand description
Watch the library at the given Path.
The given Path should point to the Cargo.toml of the package used to build the library.
When a library is being “watched”, the library will be re-built any time some filesystem event occurs within the library’s source directory. The target used is the first “dylib” discovered within the package.
The notify crate is used to watch for file-system events in a cross-platform manner.
Examples found in repository?
examples/demo.rs (line 6)
1fn main() {
2 let test_crate_path = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
3 .join("test_crate")
4 .join("Cargo.toml");
5 println!("Begin watching for changes to {:?}", test_crate_path);
6 let watch = hotlib::watch(&test_crate_path).unwrap();
7 let mut lib = watch.package().build().unwrap().load().unwrap();
8 loop {
9 unsafe {
10 let foo: libloading::Symbol<fn(i32, i32) -> i32> = lib.get(b"foo").unwrap();
11 let res = foo(6, 7);
12 println!("{}", res);
13 }
14 println!("Awaiting next change...");
15 let pkg = watch.next().unwrap();
16 lib = pkg.build().unwrap().load().unwrap();
17 }
18}