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

Manages watches a library (dylib) file, loads it using libloading::Library and provides access to its symbols. When the library changes, LibReloader is able to unload the old version and reload the new version through LibReloader::update.

Note that the LibReloader itself will not actively update, i.e. does not manage an update thread calling the update function. This is normally managed by the hot_lib_reloader_macro::hot_module macro that also manages the about-to-load and load notifications.

It can load symbols from the library with LibReloader::get_symbol.

Implementations§

source§

impl LibReloader

source

pub fn new( lib_dir: impl AsRef<Path>, lib_name: impl AsRef<str>, file_watch_debounce: Option<Duration>, loaded_lib_name_template: Option<String> ) -> Result<Self, HotReloaderError>

Creates a LibReloader. lib_dir is expected to be the location where the library to use can be found. Probably target/debug normally. lib_name is the name of the library, not(!) the file name. It should normally be just the crate name of the cargo project you want to hot-reload. LibReloader will take care to figure out the actual file name with platform-specific prefix and extension.

source

pub fn update(&mut self) -> Result<bool, HotReloaderError>

Checks if the watched library has changed. If it has, reload it and return true. Otherwise return false.

source

pub unsafe fn get_symbol<T>( &self, name: &[u8] ) -> Result<Symbol<'_, T>, HotReloaderError>

Get a pointer to a function or static variable by symbol name. Just a wrapper around libloading::Library::get.

The symbol may not contain any null bytes, with the exception of the last byte. Providing a null-terminated symbol may help to avoid an allocation. The symbol is interpreted as is, no mangling.

Safety

Users of this API must specify the correct type of the function or variable loaded.

Trait Implementations§

source§

impl Drop for LibReloader

Deletes the currently loaded lib file if it exists

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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.