Expand description
§Dolphin
A lightweight and safe Rust FFI library for dynamically loading and invoking
functions from shared libraries (.dll, .so, .dylib).
§Features
- Dynamic loading of functions from any shared library at runtime
- Safe API wrapping unsafe FFI calls
- Pre-load function addresses for zero-overhead repeated calls
- Cross-platform support (Windows, Linux, macOS)
§Quick Start
use dolphin::load_and_invoke;
// Call a C function with a string
let message = "Hello from Rust!";
load_and_invoke("./mylib.dylib", "print_message", message.as_bytes())
.expect("Failed to call function");
// Call with integer array
let numbers = vec![10, 20, 30, 40, 50];
load_and_invoke("./mylib.dylib", "calculate_sum", &numbers)
.expect("Failed to call function");§High-Performance Pattern
For repeated calls, pre-load the function once:
use dolphin::{load, invoke};
// Load once
let print_addr = load("./mylib.dylib", "print_message")
.expect("Failed to load function");
// Invoke many times with zero loading overhead
for i in 0..1000 {
let msg = format!("Message {}", i);
invoke(print_addr, msg.as_bytes()).ok();
}Functions§
- invoke
- Invokes a pre-loaded function using its memory address.
- invoke_
with_ return - Invokes a pre-loaded function that returns a value.
- load
- Loads a function from a shared library and returns its memory address.
- load_
and_ invoke - Loads a function from a shared library and executes it with the given arguments.
- load_
and_ invoke_ with_ return - Loads a function from a shared library, executes it, and returns a value.
- load_
with_ return - Loads a function that returns a value from a shared library.