Crate uniffi[][src]

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 ViaFfi trait, which must be implemented for any type that can be passed across the FFI, and which determines:

  • How to represent values of that type in the low-level C-style type system of the FFI layer.
  • How to “lower” rust values of that type into an appropriate low-level FFI value.
  • How to “lift” low-level FFI values back into rust values of that type.
  • How to write rust values of that type into a buffer, for cases where they are part of a compound data structure that is serialized for transfer.
  • How to read rust values of that 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 ViaFfi trait, we provide a handful of struct definitions useful for passing core rust types over the FFI, such as RustBuffer.

Re-exports

pub use ffi::*;

Modules

deps
ffi
testing

Runtime support functionality for testing generated bindings.

Traits

ViaFfi

Trait defining how to transfer values via the FFI layer.

Functions

check_remaining

A helper function to ensure we don’t read past the end of a buffer.

lower_into_buffer

A helper function to lower a type by serializing it into a buffer.

try_lift_from_buffer

A helper function to lift a type by deserializing it from a buffer.