Stream: wit-bindgen

Topic: Proper way to implement resources in components


view this post on Zulip Sekhar Ravinutala (Apr 04 2024 at 14:33):

Not sure if this is the right stream, but what is the right way to implement a resource? I'm trying to implement a connector component that provides a connection resource. The goal is to abstract the different kinds of connections via a resource.

Now, this connection resource is getting generated as a zero variant enum (Connection) by wit-bindgen. But I can't push that to the resource table, so I'm pushing my real object (odbc_api::Connection) into the table, getting the rep, and returning an ad hoc Connection resource with that rep. And when I get the method call, I'm using the rep value to look up the odbc_api::Connection in the table.

Is this the right way? It seems a bit hacky and I was wondering if there is a better/more direct way.

view this post on Zulip Alex Crichton (Apr 04 2024 at 14:48):

In Wasmtime you'll probably want to use with: { ... } to customize the resource type to your own type so you can use the methods of ResourceTable natively

view this post on Zulip Sekhar Ravinutala (Apr 04 2024 at 16:43):

Thanks @Alex Crichton, yeah I was able to map it to my own enum with the connection variants I care about.


Last updated: Nov 22 2024 at 17:03 UTC