bytecodealliance / bytecodealliance/wasmtime

Storing references/lifetimes in preview2 tables

Open
#7,692 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
18.6k
Forks
1.8k
Avg merge
1d 18h
Merged PRs (30d)
126

Description

What's the proper way to store references from one value to another in tables?

Consider the following code, how can I store both the parent and child in a table? Could that be done without unsafe code?

```rust
struct Parent {
val: bool
}

impl Parent {
pub fn get_child<'a>(&'a self) -> Child<'a> {
Child {
val: &self.val
}
}
}

struct Child<'a> {
val: &'a bool,
}

fn main() {
let mut table = wasmtime_wasi::preview2::Table::new();

let parent = Parent {
val: true,
};
let child = parent.get_child();

let parent = table.push(parent).unwrap();

// can this be done somehow?
table.push_child(child, &parent);
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.