Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Rust bindings for libffi

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
NotificationsYou must be signed in to change notification settings

libffi-rs/libffi-rs

Repository files navigation

GitHub Workflow StatusDocumentationCrates.ioLicense: MITLicense: Apache 2.0

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.

Repository Layout

This repository is a Cargo workspace containing bothlibffi andlibffi-sys.

Usage

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.

Examples

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

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published

Contributors40


[8]ページ先頭

©2009-2025 Movatter.jp