#ffi #bindgen


a multi-language bindings generator for rust (runtime support code)

1 unstable release

0.23.0 Jan 27, 2023

#204 in FFI

Download history 5185/week @ 2023-02-04 6372/week @ 2023-02-11 6918/week @ 2023-02-18 6680/week @ 2023-02-25 7635/week @ 2023-03-04 7498/week @ 2023-03-11 7246/week @ 2023-03-18 8079/week @ 2023-03-25 6736/week @ 2023-04-01 6115/week @ 2023-04-08 6418/week @ 2023-04-15 5971/week @ 2023-04-22 6434/week @ 2023-04-29 8080/week @ 2023-05-06 5681/week @ 2023-05-13 6008/week @ 2023-05-20

26,811 downloads per month
Used in 6 crates (via uniffi)

MPL-2.0 license

861 lines

Runtime support code for uniffi

This crate provides the small amount of runtime code that is required by the generated uniffi component scaffolding in order to transfer data back and forth across the C-style FFI layer, as well as some utilities for testing the generated bindings.

The key concept here is the [FfiConverter] trait, which is responsible for converting between a Rust type and a low-level C-style type that can be passed across the FFI:

  • How to represent values of the Rust type in the low-level C-style type system of the FFI layer.
  • How to "lower" values of the Rust type into an appropriate low-level FFI value.
  • How to "lift" low-level FFI values back into values of the Rust type.
  • How to write values of the Rust type into a buffer, for cases where they are part of a compound data structure that is serialized for transfer.
  • How to read values of the Rust type from buffer, for cases where they are received as part of a compound data structure that was serialized for transfer.

This logic encapsulates the Rust-side handling of data transfer. Each foreign-language binding must also implement a matching set of data-handling rules for each data type.

In addition to the core FfiConverter trait, we provide a handful of struct definitions useful for passing core rust types over the FFI, such as [RustBuffer].


~48K SLoC