Struct hotlib::TempLibrary [−][src]
pub struct TempLibrary { /* fields omitted */ }
Expand description
A wrapper around a libloading::Library
that cleans up the library on Drop
.
Implementations
The inner libloading::Library
.
This may also be accessed via the Deref
implementation.
The time at which the original library was built.
Methods from Deref<Target = Library>
Get a pointer to function or static variable by symbol name.
The symbol
may not contain any null bytes, with an exception of last byte. A null
terminated symbol
may avoid a string allocation in some cases.
Symbol is interpreted as-is; no mangling is done. This means that symbols like x::y
are
most likely invalid.
Safety
Pointer to a value of arbitrary type is returned. Using a value with wrong type is undefined.
Platform-specific behaviour
Implementation of thread local variables is extremely platform specific and uses of these variables that work on e.g. Linux may have unintended behaviour on other POSIX systems or Windows.
On POSIX implementations where the dlerror
function is not confirmed to be MT-safe (such
as FreeBSD), this function will unconditionally return an error the underlying dlsym
call
returns a null pointer. There are rare situations where dlsym
returns a genuine null
pointer without it being an error. If loading a null pointer is something you care about,
consider using the os::unix::Library::get_singlethreaded
call.
Examples
Given a loaded library:
let lib = Library::new("/path/to/awesome.module").unwrap();
Loading and using a function looks like this:
unsafe { let awesome_function: Symbol<unsafe extern fn(f64) -> f64> = lib.get(b"awesome_function\0").unwrap(); awesome_function(0.42); }
A static variable may also be loaded and inspected:
unsafe { let awesome_variable: Symbol<*mut f64> = lib.get(b"awesome_variable\0").unwrap(); **awesome_variable = 42.0; };
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for TempLibrary
impl Send for TempLibrary
impl Sync for TempLibrary
impl Unpin for TempLibrary
impl UnwindSafe for TempLibrary