Hi, all. I am wondering what the best way to store state in the Guest struct is when implementing the Guest trait after wit_bindgen::generate.
Ideally I would be able to define fields in the struct for which I am defining the impl. However, there is no self paramter. All the functions are associated functions. Is the only option to store state in global variables?
Thank you.
Yes you'll have to use global state because these are global functions
Do you happen to have any examples for a good convention for that? Or is it just something like OnceCell with a mutex?
Hey all. Random question: I'm curious what the general performance characteristics are of passing resource types between components. Can it be expected to be fairly fast?
I'm just wondering because I'm used to the JNI, where doing similar things is generally considered to be fairly slow. Is the situation better for WASM?
The larger motivation behind this is I'm trying to figure out the most efficient way to design a wit world for multi-platform UI development. Currently in my prototype I have a resource type for views basically, but I'm wondering if that's the right approach, or if I should try something else (e.x. passing a single representation of the entire UI layout in a single call by value -- so using something like a DOM represented with variants / records basically).
I know I won't get a more concrete answer until I bench this myself, but I'm curious if anyone had any general thoughts.
Oof, sorry. New to zulip. I think I should have made a new topic for this. :(
I had the same question and if I understand it correctly we should be able to use resources for this. The Rust example in this book has a section on implementing resources.
I broke the second link, it should be https://component-model.bytecodealliance.org/language-support/rust.html#using-resources.
Nevermind, global variables are probably better for this :thinking:
Last updated: Dec 06 2025 at 07:03 UTC