dylink 0.7.0

Run-time dynamic linking loader utilities
Documentation

Dylink

Crates.io Crates.io Crates.io docs.rs dylink-rs unsafe:yes

Dylink provides a run-time dynamic linking framework for lazily evaluating shared libraries. When functions are loaded they are evaluated through a thunk for first time calls, which loads the function from its respective library. Preceeding calls after initialization have no overhead or additional branching checks, since the thunk is replaced by the loaded function.

This crate can be used with other library loaders by making a wrapper around your favorite loader and implementing the Loader trait.


Related links:

Features

  • Thread-safe library loading.
  • Fearless closing - closing never invalidates symbols.
  • Branchless symbols - loaded symbols have zero overhead.

Supported platforms

Implemented for all major platforms.

Windows Linux MacOS
YES YES YES

Usage

Add this to your Cargo.toml

[dependencies]

dylink = "0.7"

Example

Below is a basic working example on how to use the macro on windows.

use dylink::*;

static KERNEL32: Library<SystemLoader> = Library::new(&["Kernel32.dll"]);

#[dylink(library=KERNEL32)]
extern "stdcall" {
    fn GetLastError() -> u32;
    fn SetLastError(_: u32);
}

unsafe {
   SetLastError(52);
   assert_eq!(52, GetLastError());
}

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.