- Notifications
You must be signed in to change notification settings - Fork54
Rust bindings for libffi
License
Apache-2.0, MIT licenses found
Licenses found
libffi-rs/libffi-rs
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
libffi-rs: Rust bindings forlibffi
The C libffi library provides two main facilities: assembling callsto functions dynamically, and creating closures that can be calledas ordinary C functions. In Rust, the latter means that we can turna Rust lambda (or any object implementingFn/FnMut) into anordinary C function pointer that we can pass as a callback to C.
This repository is a Cargo workspace containing bothlibffi andlibffi-sys.
Buildinglibffi will buildlifbffi-sys, which will in turn build thelibffi C libraryfrom github, whichrequires that you have a working make, C compiler, automake, andautoconf first. It’son crates.io, soyou can add
[dependencies]libffi ="4.1.1"
to yourCargo.toml.
This crate depends onthelibffi-sys crate, which by defaultattempts to build its own version of the C libffi library. In order touse your system’s C libffi instead, enable this crate’ssystemfeature in yourCargo.toml:
[features]libffi = {version ="4.1.1",features = ["system"] }
Seethelibffi-sys documentation for more information about how itfinds C libffi.
This crate supports Rust version 1.78 and later.
In this example, we convert a Rust lambda containing a free variableinto an ordinary C code pointer. The type offun below isextern "C" fn(u64, u64) -> u64.
use libffi::high::Closure2;fnmain(){let x =5u64;let f = |y:u64,z:u64| x + y + z;let closure =Closure2::new(&f);let fun = closure.code_ptr();assert_eq!(18, fun(6,7));}
More examples are available in theexamples folder.
About
Rust bindings for libffi
Resources
License
Apache-2.0, MIT licenses found
Licenses found
Uh oh!
There was an error while loading.Please reload this page.