1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
//! Rust-owned references to WebAssembly GC objects.
//!
//! Define structs with [`macro@wasmgc`], allocate them with [`Gc`], and store
//! sequences in [`GcArray`]. Objects live in the engine's GC heap; Rust values
//! own the roots that keep those objects reachable. [`ExternRef`] stores host
//! values such as JavaScript objects alongside GC references and scalars.
//!
//! The runtime is intended for `wasm32-unknown-unknown` and
//! `wasm64-unknown-unknown`. Compile the application to Wasm, then run the
//! `wasmgc` post-link tool before instantiating it in an engine with WasmGC
//! support. The tool supplies the GC instructions and reference adapters that
//! ordinary Rust compilation cannot express directly.
//!
//! # Example
//!
//! A cloned root observes writes to the same counter:
//!
//! ```no_run
//! use wasmgc::{Gc, wasmgc};
//!
//! #[wasmgc]
//! struct Counter {
//! value: i32,
//! }
//!
//! let counter = Gc::new(Counter { value: 1 });
//! let shared = counter.clone();
//! shared.set_value(2);
//! assert_eq!(counter.value(), 2);
//! assert!(Gc::ref_eq(&counter, &shared));
//! ```
//!
//! This example runs inside a post-processed Wasm module. It is not a native
//! host program.
//!
//! # Ownership and storage
//!
//! Moving a [`Gc`] transfers its root. Cloning allocates another root for the
//! same object, and dropping releases that root. An object becomes collectible
//! once no Rust root, host reference, or reachable GC object keeps it alive.
//! This permits cyclic object graphs without reference-counted cycles.
//!
//! A struct definition supplies construction values and a schema, rather than
//! an addressable Rust payload in the GC heap. Its generated getters copy
//! scalars or acquire owned references; setters borrow reference arguments
//! until the write completes. There is no `&T` into a GC object, and managed
//! objects do not run Rust destructors. Roots belong to their Wasm instance and
//! cannot be sent across threads.
//!
//! [`GcStruct`] describes a struct and its generated view. [`GcHeapObj`]
//! describes either a struct or an [`Array`] heap type. [`GcValue`] defines the
//! scalar and reference conversions used by fields, array elements, and
//! imported or exported functions. Most applications use the macro and the
//! built-in implementations of these traits.
//!
//! # Host functions
//!
//! Apply [`macro@wasmgc`] to a function to export it, or to an
//! `extern "wasmgc"` block to import host functions. After post-processing,
//! their reference parameters and results are actual Wasm references. The
//! macro documentation covers constructors, field exports, and host contracts.
//!
//! # Cargo features
//!
//! - **`alloc`** (enabled by default): adds conversions to and from `Vec`.
//! Slice copies and GC allocations remain available without it.
//! - **`cli`**: enables the host-side `wasmgc::process` function and the
//! `wasmgc` executable. It also enables `std` and the Wasm binary tools used
//! by post-processing. Application dependencies normally leave it disabled.
//!
//! Without `cli`, this crate is `no_std`. It does not replace the Rust
//! allocator: Rust buffers and GC objects have separate storage and lifetimes.
extern crate alloc;
pub use wasmgc;
pub use ;
pub use ExternRef;
pub use ;
pub use process;
pub use GcValue;