<commit_before># libffi-rs

Rust bindings for [libffi](https://sourceware.org/libffi/).

The C libffi library provides two main facilities: assembling calls
to functions dynamically, and creating closures that can be called
as ordinary C functions. In Rust, the latter means that we can turn
a Rust lambda (or any object implementing `Fn`/`FnMut`) into an
ordinary C function pointer that we can pass as a callback to C.

The easiest way to use this library is via the `high` layer module, but
more flexibility (and less checking) is provided by the `middle` and
`low` layers.

# Usage/Warning

This library is experimental/unstable and shouldn’t be used for
anything yet. If it does something you need or want to play with
then we should talk.

It’s [on crates.io](https://crates.io/crates/libffi), so you can be
used by adding `libffi` to the dependencies in your project’s
`Cargo.toml`:

```toml
[dependencies]
libffi = "0.1"
```

However, to actually use it, you need to install [Rust
bindgen](https://crates.io/crates/bindgen) (0.18.0) and [C
libffi](https://sourceware.org/libffi/) (3.2.1) manually first.

# Example

In this example, we convert a Rust lambda containing a free variable
into an ordinary C code pointer. The type of `fun` below is
`extern "C" fn(u64, u64) -> u64`.

```rust
use libffi::high::Closure2;

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));
```

## Building

I’m writing this section to document my build process.

  - Installed pkg-config: brew install pkg-config

  - Installed libffi 3.2.1 (rather than OS X system libffi, which is old)

      - brew install autoconf automake
<commit_msg>Documentation formatting.<commit_after># libffi-rs

Rust bindings for [libffi](https://sourceware.org/libffi/).

The C libffi library provides two main facilities: assembling calls
to functions dynamically, and creating closures that can be called
as ordinary C functions. In Rust, the latter means that we can turn
a Rust lambda (or any object implementing `Fn`/`FnMut`) into an
ordinary C function pointer that we can pass as a callback to C.

The easiest way to use this library is via the `high` layer module, but
more flexibility (and less checking) is provided by the `middle` and
`low` layers.

## Usage/Warning

This library is experimental/unstable and shouldn’t be used for
anything yet. If it does something you need or want to play with
then we should talk.

It’s [on crates.io](https://crates.io/crates/libffi), so you can be
used by adding `libffi` to the dependencies in your project’s
`Cargo.toml`:

```toml
[dependencies]
libffi = "0.1"
```

However, to actually use it, you need to install [Rust
bindgen](https://crates.io/crates/bindgen) (0.18.0) and [C
libffi](https://sourceware.org/libffi/) (3.2.1) manually first.

## Example

In this example, we convert a Rust lambda containing a free variable
into an ordinary C code pointer. The type of `fun` below is
`extern "C" fn(u64, u64) -> u64`.

```rust
use libffi::high::Closure2;

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));
```

## Building

I’m writing this section to document my build process.

  - Installed pkg-config: brew install pkg-config

  - Installed libffi 3.2.1 (rather than OS X system libffi, which is old)

      - brew install autoconf automake

{'fraction_non_alphanumeric': 0.1043956043956044, 'fraction_numerical': 0.017929438982070563, 'mean_word_length': 4.064421669106881, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1904630', 'n_tokens_mistral': 1182, 'n_tokens_neox': 1104, 'n_words': 483}