Struct libloading::Library [] [src]

pub struct Library(_);

A dynamically loaded library.

Methods

impl Library
[src]

fn new<P: AsRef<OsStr>>(filename: P) -> Result<Library>

Find and load a shared library (module).

Locations where library is searched for is platform specific and can’t be adjusted portably.

Examples

// on Unix
let lib = Library::new("libm.so.6").unwrap();
// on OS X
let lib = Library::new("libm.dylib").unwrap();
// on Windows
let lib = Library::new("msvcrt.dll").unwrap();

unsafe fn get<'lib, T>(&'lib self, symbol: &[u8]) -> Result<Symbol<'lib, T>>

Get a symbol by name.

Mangling or symbol rustification is not done: trying to get something like x::y will not work.

You may append a null byte at the end of the byte string to avoid string allocation in some cases. E.g. for symbol sin you may write b"sin\0" instead of b"sin".

Unsafety

Symbol of arbitrary requested type is returned. Using a symbol with wrong type is not memory safe.

Examples

Simple function:

let sin: Symbol<extern fn(f64) -> f64> = unsafe {
    lib.get(b"sin\0").unwrap()
};

A static or TLS variable:

let errno: Symbol<*mut u32> = unsafe {
    lib.get(b"errno\0").unwrap()
};