Hello, was wondering, I am defining some resources in my wit file but having a problem defining a constructor that contains a mutable reference of another resource. Would prefer not to use mutexs but if there is no other way that is fine as well. Was wondering if it was possible?
in wasmtime-wasi, when we need to store a reference to one host resource in another host resource, we do so by storing the table index to one inside the other
and we also make sure that the resource containing the reference is inserted into the ResourceTable as a child of the referent, which ensures that the referent outlives the reference
in general though this is a tricky design space because the rules for resources dont fit neatly into the rust type system. see, for more discussion and context, https://github.com/bytecodealliance/wasmtime/pull/7902 and https://github.com/bytecodealliance/wasmtime/pull/7812
basically, we designed the resource type system to be maximally useful by components, not to make the host implementation straightforward
Interesting! I will read this and the links through to better understand. Thank you!
for sure. happy to talk more about it, its a really tricky topic, and we dont have all the answers yet.
Last updated: Dec 23 2024 at 14:03 UTC