Stream: git-wasmtime

Topic: wasmtime / issue #7692 Storing references/lifetimes in pr...


view this post on Zulip Wasmtime GitHub notifications bot (Dec 15 2023 at 02:47):

MendyBerger opened issue #7692:

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?

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();

    table.push_child(child, &parent);
}

view this post on Zulip Wasmtime GitHub notifications bot (Dec 15 2023 at 02:57):

MendyBerger edited issue #7692:

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?

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);
}

view this post on Zulip Wasmtime GitHub notifications bot (Dec 15 2023 at 16:17):

alexcrichton commented on issue #7692:

This unfortunately cannot be done at this time. Using push_child you should be able to store indexes to other items, however (rather than references).


Last updated: Nov 22 2024 at 16:03 UTC