wac_graph/lib.rs
1//! A library for defining, encoding, and decoding WebAssembly composition graphs.
2//!
3//! An example of composing two components together using a `CompositionGraph`:
4//!
5//! ```rust,no_run
6//! use wac_graph::{CompositionGraph, EncodeOptions, types::Package};
7//!
8//! # fn main() -> anyhow::Result<()> {
9//! let mut graph = CompositionGraph::new();
10//!
11//! // Register the packages with the graph
12//! // It is assumed that `my:package1` exports a function named `a`,
13//! // while `my:package2` imports a function named `b`.
14//! let pkg = Package::from_file("my:package1", None, "package1.wasm", graph.types_mut())?;
15//! let package1 = graph.register_package(pkg)?;
16//! let pkg = Package::from_file("my:package2", None, "package2.wasm", graph.types_mut())?;
17//! let package2 = graph.register_package(pkg)?;
18//!
19//! // Instantiate package `my:package1`
20//! let instantiation1 = graph.instantiate(package1);
21//!
22//! // Alias the `a` export of the `my:package1` instance
23//! let a = graph.alias_instance_export(instantiation1, "a")?;
24//!
25//! // Instantiate package `my:package2`
26//! let instantiation2 = graph.instantiate(package2);
27//!
28//! // Set argument `b` of the instantiation of `my:package2` to `a`
29//! graph.set_instantiation_argument(instantiation2, "b", a)?;
30//!
31//! // Finally, encode the graph into a new component
32//! let bytes = graph.encode(EncodeOptions::default())?;
33//!
34//! # Ok(())
35//! # }
36//! ````
37
38#![deny(missing_docs)]
39
40pub(crate) mod encoding;
41mod graph;
42mod plug;
43
44pub use graph::*;
45pub use plug::*;
46pub use wac_types as types;