pub struct Watch { /* private fields */ }Expand description
Watches and re-builds the library upon changes to its source code.
Implementations§
Source§impl Watch
impl Watch
Sourcepub fn manifest_path(&self) -> &Path
pub fn manifest_path(&self) -> &Path
The path to the package’s Cargo.toml.
Sourcepub fn next(&self) -> Result<Package<'_>, NextError>
pub fn next(&self) -> Result<Package<'_>, NextError>
Wait for the library to be re-built after some change.
Examples found in repository?
examples/demo.rs (line 15)
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}Sourcepub fn try_next(&self) -> Result<Option<Package<'_>>, NextError>
pub fn try_next(&self) -> Result<Option<Package<'_>>, NextError>
The same as next, but returns early if there are no pending events.
Sourcepub fn package(&self) -> Package<'_>
pub fn package(&self) -> Package<'_>
Manually retrieve the library’s package immediately without checking for file events.
This is useful for triggering an initial build during model initialisation.
Examples found in repository?
examples/demo.rs (line 7)
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}Auto Trait Implementations§
impl !Freeze for Watch
impl RefUnwindSafe for Watch
impl Send for Watch
impl Sync for Watch
impl Unpin for Watch
impl UnsafeUnpin for Watch
impl UnwindSafe for Watch
Blanket Implementations§
impl<T> Any for Twhere
T: Any,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more