Skip to content

Commit

Permalink
version 0.5.0
Browse files Browse the repository at this point in the history
Signed-off-by: Victor Berger <victor.berger@m4x.org>
  • Loading branch information
elinorbgr committed Feb 25, 2021
1 parent 210e501 commit 0e972dc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
[package]
name = "dlib"
version = "0.4.2"
version = "0.5.0"
repository = "https://github.com/vberger/dlib"
authors = ["Victor Berger <victor.berger@m4x.org>"]
license = "MIT"
description = "Helper macros for handling manually loading optional system libraries."
exclude = ["/dlib-test", "README.tpl"]
readme = "README.md"

[dependencies]
libloading = "0.7"
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,23 @@ pub struct Foo {


impl Foo {
pub fn open(name: &str) -> Result<Foo, DlError> { /* ... */ }
pub unsafe fn open(name: &str) -> Result<Foo, DlError> { /* ... */ }
}
```

This method returns `Ok(..)` if the loading was successful. It contains an instance of the defined struct
with all of its fields pointing to the appropriate symbol.

If the library specified by `name` could not be found, it returns `Err(DlError::NotFount)`.
If the library specified by `name` could not be openened, it returns `Err(DlError::CantOpen(e))`, with
`e` the error reported by `libloading` (see [LibLoadingError]);

It will also fail on the first missing symbol, with `Err(DlError::MissingSymbol(symb))` where `symb`
is a `&str` containing the missing symbol name.

Note that this method is unsafe, as loading (and unloading on drop) an external C library can run arbitrary
code. As such, you need to ensure that the specific library you want to load is safe to load in the context
you want to load it.

### Remaining generic in your crate

If you want your crate to remain generic over dlopen vs. linking, simply add a feature to your `Cargo.toml`:
Expand Down

0 comments on commit 0e972dc

Please sign in to comment.