8 releases (major breaking)

Uses old Rust 2015

7.0.0 Feb 10, 2017
6.0.0 Oct 1, 2016
5.0.0 Sep 2, 2016
4.0.0 Sep 2, 2016
0.2.0 May 13, 2016

#368 in Operating systems

Download history 120/week @ 2023-11-19 244/week @ 2023-11-26 280/week @ 2023-12-03 222/week @ 2023-12-10 184/week @ 2023-12-17 23/week @ 2023-12-24 84/week @ 2023-12-31 149/week @ 2024-01-07 97/week @ 2024-01-14 156/week @ 2024-01-21 152/week @ 2024-01-28 188/week @ 2024-02-04 259/week @ 2024-02-11 206/week @ 2024-02-18 250/week @ 2024-02-25 239/week @ 2024-03-03

966 downloads per month
Used in 17 crates (3 directly)

ISC license

63KB
809 lines

Contains (JAR file, 54KB) gradle/wrapper/gradle-wrapper.jar

sharedlib Travis CI Appveyor CI

A cross-platform shared library loader.

(crates.io) (docs)

Based on libloading by Simonas Kazlauskas.

sharedlib is a crate for loading shared libraries at runtime. This is a useful primitive for implementing other things like plugins. The advantage of this crate over other shared library crates is that it provides both lifetime-bound and ref-counted libraries, and it allows both functions and data to be loaded.

Quickstart

To load a library you can use any of the Lib, LibTracked, or LibUnsafe structs. Each of these structs provides different guarantees. For more information about the guarantees they provide see the choosing your guarantees section in the docs. We use Lib for the examples below:

Calling a function in another library

unsafe {
    let path_to_lib = "examplelib.dll";
    let lib = try!(Lib::new(path_to_lib));
    let hello_world_symbol: Func<extern "C" fn()> = try!(lib.find_func("hello_world"));
    let hello_world = hello_world_symbol.get();
    hello_world();
}

Accessing data in another library

unsafe {
    let path_to_lib = "examplelib.dll";
    let lib = try!(Lib::new(path_to_lib));
    let my_usize_symbol: Data<usize> = try!(lib.find_data("my_usize"));
    let my_usize = my_usize_symbol.get();
    assert_eq!(*my_usize, 0);
}

Additional information

Plenty of additional information can be found in the docs.

Dependencies

~155KB