Crate snek [] [src]

This library provides a convenient interface for loading dynamic libraries at runtime, and for retrieving symbols from them. The recommended use is via the snek! macro, which defines a structure which loads symbols on construction and has methods for each one, however it is also possible to manually load libraries and symbols using a Snek instance.


There is no way of verifying the type of loaded symbols, so both methods of using them assume that the given type is correct - this library should be used very carefully. Consider everything very unstable at the moment.


#[macro_use] extern crate snek;
extern crate libc;

use libc::c_int;

snek! {
    Example {
        hello: () -> (),
        add: (x: c_int, y: c_int) -> c_int

fn main() {
    if let Ok(example) = Example::load("") {
        unsafe { example.hello() };
        println!("2 + 4 = {}", unsafe { example.add(2, 4) });



This macro is used to generate a struct that wraps a dynamic library with generated loading code. Each defined function will be loaded as a symbol from the library when an instance of the struct is constructed, and can be called via functions of the same name attached to the struct.



This provides an interface for manually loading a dynamic library and symbols from it. While this exists, it is more recommended to use the snek! macro to generate a wrapper for a library automatically.


This provides an interface around a symbol loaded from a dynamic library. This should not be constructed manually, but returned from Snek::symbol or used internally via the snek! macro.



This enum stores information about the error returned when loading a library or symbol fails. On unix platforms, it hold the result of dlerror().