changelog.rs |
The change log. |
16007 |
error.rs |
|
4901 |
lib.rs |
Bindings around the platform's dynamic library loading primitives with greatly improved memory safety.
Using this library allows the loading of [dynamic libraries](struct.Library.html), also known as
shared libraries, and the use of the functions and static variables they contain.
The `libloading` crate exposes a cross-platform interface to load a library and make use of its
contents, but little is done to hide the differences in behaviour between platforms.
The API documentation strives to document such differences as much as possible.
Platform-specific APIs are also available in the [`os`](crate::os) module. These APIs are more
flexible, but less safe.
# Installation
Add the `libloading` library to your dependencies in `Cargo.toml`:
```toml
[dependencies]
libloading = "0.8"
```
# Usage
In your code, run the following:
```no_run
fn call_dynamic() -> Result<u32, Box<dyn std::error::Error>> {
unsafe {
let lib = libloading::Library::new("/path/to/liblibrary.so")?;
let func: libloading::Symbol<unsafe extern fn() -> u32> = lib.get(b"my_func")?;
Ok(func())
}
}
```
The compiler will ensure that the loaded function will not outlive the `Library` from which it comes,
preventing the most common memory-safety issues. |
2721 |
os |
|
|
safe.rs |
|
11082 |
test_helpers.rs |
This is a separate file containing helpers for tests of this library. It is built into a
dynamic library by the build.rs script. |
747 |
util.rs |
|
1050 |