Module uniffi::metadata

Expand description

Pack UniFFI interface metadata into byte arrays

In order to generate foreign bindings, we store interface metadata inside the library file using exported static byte arrays. The foreign bindings code reads that metadata from the library files and generates bindings based on that.

The metadata static variables are generated by the proc-macros, which is an issue because the proc-macros don’t have knowledge of the entire interface – they can only see the item they’re wrapping. For example, when a proc-macro sees a type name, it doesn’t know anything about the actual type: it could be a Record, an Enum, or even a type alias for a Vec<>/Result<>.

This module helps bridge the gap by providing tools that allow the proc-macros to generate code to encode the interface metadata:

  • A set of const functions to build up metadata buffers with const expressions
  • The export_static_metadata_var! macro, which creates the static variable from a const metadata buffer.
  • The FfiConverter::TYPE_ID_META const which encodes an identifier for that type in a metadata buffer.

uniffi_bindgen::macro_metadata contains the code to read the metadata from a library file. fixtures/metadata has the tests.

Modules

  • Metadata constants, make sure to keep this in sync with copy in uniffi_meta::reader

Structs

Functions