pub struct LibReloadObserver { /* private fields */ }
Expand description

A LibReloadObserver allows to wait for library changes. See

You can use those methods individually or in combination. In particular, if you want to serialize state before a library change happens and then deserialize / migrate it when the library update is done, using both methods in combination is quite useful. Something along the lines of:

#[hot_module(dylib = "lib")]
mod hot_lib {
    #[lib_change_subscription]
    pub fn subscribe() -> hot_lib_reloader::LibReloadObserver { }
}

fn test() {
    let lib_observer = hot_lib::subscribe();

    /* ... */

    // wait for reload to begin (at this point the  old version is still loaded)
    let update_blocker = lib_observer.wait_for_about_to_reload();

    /* do update preparations here, e.g. serialize state */

    // drop the blocker to allow update
    drop(update_blocker);

    // wait for reload to be completed
    lib_observer.wait_for_reload();

    /* new lib version is loaded now so you can e.g. restore state */
}

Implementations§

source§

impl LibReloadObserver

source

pub fn wait_for_about_to_reload(&self) -> BlockReload

A call to this method will do a blocking wait until the watched library is about to change. It returns a BlockReload token. While this token is in scope you will prevent the pending update to proceed. This is useful for doing preparations for the update and while the old library version is still loaded. You can for example serialize state.

source

pub fn wait_for_about_to_reload_timeout( &self, timeout: Duration ) -> Option<BlockReload>

Like Self::wait_for_about_to_reload but for a limited time. In case of a timeout return None.

source

pub fn wait_for_reload(&self)

Will do blocking wait until a new library version is loaded.

source

pub fn wait_for_reload_timeout(&self, timeout: Duration) -> bool

Like Self::wait_for_reload but for a limited time. In case of a timeout return false.

Auto Trait Implementations§

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>,

§

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>,

§

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.