Skip to content

Commit bc5a503

Browse files
committed
fix examples
1 parent a783c40 commit bc5a503

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

examples/anyref.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ fn main() -> Result<()> {
5454
assert_eq!(ret.unwrap().unwrap_i31(&store)?, I31::wrapping_u32(42));
5555

5656
println!("GCing within the store...");
57-
store.gc();
57+
store.gc(None);
5858

5959
println!("Done.");
6060
Ok(())

examples/externref.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,17 @@ fn main() -> Result<()> {
1818
let instance = Instance::new(&mut store, &module, &[])?;
1919

2020
println!("Creating new `externref`...");
21-
let externref = ExternRef::new(&mut store, "Hello, World!")?;
21+
let externref = match ExternRef::new(&mut store, "Hello, World!") {
22+
Ok(x) => x,
23+
Err(e) => match e.downcast::<GcHeapOutOfMemory<&str>>() {
24+
Ok(oom) => {
25+
let (inner, oom) = oom.take_inner();
26+
store.gc(Some(&oom));
27+
ExternRef::new(&mut store, inner)?
28+
}
29+
Err(e) => return Err(e),
30+
},
31+
};
2232
assert!(externref
2333
.data(&store)?
2434
.expect("should have host data")
@@ -58,7 +68,7 @@ fn main() -> Result<()> {
5868
assert!(Rooted::ref_eq(&store, &ret.unwrap(), &externref)?);
5969

6070
println!("GCing within the store...");
61-
store.gc();
71+
store.gc(None);
6272

6373
println!("Done.");
6474
Ok(())

0 commit comments

Comments
 (0)