Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Rust API Map

A map of the public API: what a Rust producer uses from the weaveffi crate, and the entry points of the crates tools build on. cargo doc has the full signatures; this page says which items you’ll reach for.

[dependencies]
weaveffi = "0.25"

The weaveffi crate

ItemPurpose
#[weaveffi::export]Exports a function, or every pub fn of an interface’s inherent impl block as a constructor, method, or static. An async fn is async, cancellable when its last parameter is a CancelToken; a Result return throws its error type (a domain, or any for an untyped error). #[weaveffi(skip)] leaves a member out.
#[weaveffi::record]A struct with named fields, crossing by value.
#[weaveffi::enumeration]A C-style enum, or a rich enum whose variants carry named fields.
#[weaveffi::error]An error domain: explicit positive codes, optional fields, and a generated Display (from #[weaveffi(message = "...")] templates or the variants’ docs) and std::error::Error, unless written #[weaveffi::error(no_display)].
#[weaveffi::interface]A reference-counted, Send + Sync object type.
#[weaveffi::callback_interface]A Send + Sync trait the consumer implements, each method returning Result<T, E> with E: From<ForeignError>; accepted as Arc<dyn Trait> or Option<Arc<dyn Trait>>.
#[weaveffi::custom(repr = R, lift = f, lower = g)]A type alias or struct that crosses as R.
weaveffi::export_runtime!()Exports the runtime symbols under the crate’s prefix and defines the crate’s tag type; call once, at the crate root.
Iter<T>The return type for iter<T>; build one with Iter::new from anything IntoIterator.
CancelTokenA cancellable async fn’s last parameter; is_cancelled() for cooperative cleanup.
ForeignErrorA consumer callback’s failure (code, message), which every callback method’s error type converts from. As an exported function’s error type it’s throws: any.
ErrorAn untyped error (throws: any) that any std::error::Error converts into with ?; Error::msg makes one from any Display.
set_spawner, Spawner, BoxFutureInstall the executor async functions run on, overriding the default (Tokio, or a thread per call without the tokio feature).

The features are tokio (default: async exports run on Tokio), leak-check (live-resource counters for {p}_debug_live), and anyhow (anyhow::Error as an untyped error). The producer macro guide covers every attribute.

The runtime the attributes expand against lives in a hidden module of the weaveffi crate. Producers never name it, and it isn’t part of the crate’s semver surface; the C ABI contract is the specification it implements.

weaveffi-model

ModulePurpose
irThe IR an IDL document or a producer’s metadata becomes: Api and its declarations, TypeRef, Throws, and CURRENT_SCHEMA_VERSION.
parseload_api (a document with every file it imports) and parse_api_str (one document), with miette diagnostics. Requires the idl feature.
validatevalidate(&api, &identity, sources), which reports every violation and builds the Model; collect_warnings for the advisory lints.
modelThe validated Model generators render from, with every C symbol and lowered signature, and ABI_VERSION.
ty, abiResolved types and their families (Ty, Family, RunKind), and the C type algebra (CType, AbiFn).
pkgPackage (the [package] table) and the resolved Identity.
contractContract ids, canonical signatures, and FNV-1a hashing.
metaThe metadata frames a producer embeds, and assemble, which turns them back into an Api.
errorsThe error-type naming rule every target shares.

weaveffi-cli

ItemPurpose
project::ProjectLocate a project as the weaveffi command does, read its API (from an IDL or a producer’s built library), and validate it into a Model.
codegen::OrchestratorRender targets and write them to an output directory, rewriting only changed files and removing stale ones.
config::ProjectConfigThe parsed weaveffi.toml.
targets::{Target, REGISTRY}The trait every generator implements and the list of registered targets.
packageThe artifact types weaveffi package writes.

Library Mode shows a build.rs that uses Project and the Orchestrator.