Skip to content
SpxgPublic

About

Using WebAssembly GC from Rust

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Repository files navigation

wasmgc

Crates.io

A Rust implementation of WasmGC.

Create and mutate objects on the WebAssembly engine's garbage-collected heap from Rust:

  • Gc<T> holds a managed object; #[wasmgc] defines structs and their accessors.
  • GcArray<T> holds a fixed-length array of scalars or references.
  • ExternRef keeps host values alive and lets GC objects store them directly.
use wasmgc::{Gc, wasmgc};

#[wasmgc]
struct Counter {
    value: i32,
}

let counter = Gc::new(Counter { value: 1 });
counter.set_value(2);
assert_eq!(counter.value(), 2);

Compile your application to Wasm, then run the wasmgc post-link tool to supply GC instructions and reference adapters. Imported and exported functions can exchange native GC references with the host.

cargo install wasmgc --features cli
wasmgc input.wasm -o output.wasm

Getting started · API reference

About

Using WebAssembly GC from Rust

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages