Skip to main content

Crate packr

Crate packr 

Source
Expand description

Composite: A package runtime with extended WIT support

This runtime extends the WebAssembly Component Model with support for recursive data types, enabling natural representation of tree structures like ASTs, S-expressions, and other recursive data.

§Architecture

┌─────────────────────────────────────────┐
│           Composite Runtime             │
│                                         │
│  types     - Unified type system        │
│  parser    - Extended WIT parsing       │
│  abi       - Type encoding/decoding     │
│  runtime   - Package instantiation      │
│                                         │
├─────────────────────────────────────────┤
│       WASM Execution (wasmtime)         │
└─────────────────────────────────────────┘

§Extended WIT Types

WIT+ allows recursive types by default:

variant sexpr {
    sym(string),
    num(s64),
    lst(list<sexpr>),
}

§Async Support

For async host functions, use AsyncRuntime:

let runtime = AsyncRuntime::new();
let module = runtime.load_module(&wasm_bytes)?;

let instance = module.instantiate_with_host_async(MyState::new(), |builder| {
    builder.interface("theater:runtime")?
        .func_async("fetch", |ctx, url: String| {
            Box::pin(async move { fetch(&url).await })
        })?;
    Ok(())
}).await?;

Re-exports§

pub use abi::decode;
pub use abi::encode;
pub use interface_impl::FuncSignature;
pub use interface_impl::HostFunc;
pub use interface_impl::InterfaceImpl;
pub use interface_impl::PackParams;
pub use interface_impl::PackType;
pub use metadata::compute_interface_hash;
pub use metadata::compute_interface_hashes;
pub use metadata::decode_metadata;
pub use metadata::decode_metadata_with_hashes;
pub use metadata::encode_metadata;
pub use metadata::encode_metadata_with_hashes;
pub use metadata::hash_function;
pub use metadata::hash_function_from_sig;
pub use metadata::hash_function_from_sig_in;
pub use metadata::hash_interface;
pub use metadata::hash_list;
pub use metadata::hash_option;
pub use metadata::hash_record;
pub use metadata::hash_result;
pub use metadata::hash_tuple;
pub use metadata::hash_type;
pub use metadata::hash_type_in;
pub use metadata::hash_variant;
pub use metadata::validate_value_in_type_space;
pub use metadata::Binding;
pub use metadata::CaseDesc;
pub use metadata::FieldDesc;
pub use metadata::FunctionSignature;
pub use metadata::InterfaceHash;
pub use metadata::MetadataError;
pub use metadata::MetadataWithHashes;
pub use metadata::PackageMetadata;
pub use metadata::ParamSignature;
pub use metadata::TypeDesc;
pub use metadata::TypeHash;
pub use metadata::TypeValidationError;
pub use metadata::HASH_BOOL;
pub use metadata::HASH_CHAR;
pub use metadata::HASH_F32;
pub use metadata::HASH_F64;
pub use metadata::HASH_FLAGS;
pub use metadata::HASH_S16;
pub use metadata::HASH_S32;
pub use metadata::HASH_S64;
pub use metadata::HASH_S8;
pub use metadata::HASH_STRING;
pub use metadata::HASH_U16;
pub use metadata::HASH_U32;
pub use metadata::HASH_U64;
pub use metadata::HASH_U8;
pub use parser::parse_pact;
pub use parser::parse_pact_dir;
pub use parser::parse_pact_dir_with_registry;
pub use parser::parse_pact_file;
pub use parser::Interface;
pub use parser::InterfaceAlias;
pub use parser::InterfacePath;
pub use parser::InterfaceTypes;
pub use parser::Metadata;
pub use parser::MetadataValue;
pub use parser::PactExport;
pub use parser::PactFileError;
pub use parser::PactImport;
pub use parser::PactInterface;
pub use parser::PactUse;
pub use parser::ResolvedScope;
pub use parser::ResolvedUse;
pub use parser::TypeDef;
pub use parser::TypeParam;
pub use parser::TypeRegistry;
pub use parser::World;
pub use parser::WorldItem;
pub use runtime::validate_instance_implements_interface;
pub use runtime::AsyncCompiledModule;
pub use runtime::AsyncCtx;
pub use runtime::AsyncInstance;
pub use runtime::AsyncRuntime;
pub use runtime::CallInterceptor;
pub use runtime::CompiledModule;
pub use runtime::Ctx;
pub use runtime::DefaultHostProvider;
pub use runtime::ErrorHandler;
pub use runtime::HostFunctionError;
pub use runtime::HostFunctionErrorKind;
pub use runtime::HostFunctionProvider;
pub use runtime::HostLinkerBuilder;
pub use runtime::Instance;
pub use runtime::InterfaceBuilder;
pub use runtime::InterfaceError;
pub use runtime::LinkerError;
pub use runtime::Runtime;
pub use transform::InterfaceTransform;
pub use transform::RpcTransform;
pub use transform::TransformRegistry;
pub use types::Arena;
pub use types::Case;
pub use types::Field;
pub use types::Function;
pub use types::Param;
pub use types::Type;
pub use types::TypePath;
pub use codegen::generate_rust;
pub use compose::ComposeError;
pub use compose::ParsedModule;
pub use compose::StaticComposer;

Modules§

abi
ABI: Type Encoding and Decoding
codegen
Code generation from Pact interfaces
compose
Static Composition for WASM Packages
interface_impl
Interface Implementation Builder
metadata
Host-side metadata types for package type information.
parser
WIT+ and Pact Parser
runtime
Package Runtime
transform
Interface Transformation System
types
Unified Type System

Structs§

Engine
An Engine which is a global context for compilation and management of wasm modules.
Module
A compiled WebAssembly module, ready to be instantiated.