Struct Watch

Source
pub struct Watch { /* private fields */ }
Expand description

Watches and re-builds the library upon changes to its source code.

Implementations§

Source§

impl Watch

Source

pub fn manifest_path(&self) -> &Path

The path to the package’s Cargo.toml.

Source

pub fn src_path(&self) -> &Path

The path to the source directory being watched.

Source

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

pub fn try_next(&self) -> Result<Option<Package<'_>>, NextError>

The same as next, but returns early if there are no pending events.

Source

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 UnwindSafe for Watch

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Any for T
where T: Any,

Source§

impl<T> Erased for T