Not sure if this is the right place or if the question makes sense, but would appreciate any help.
A project I'm working on previously used fp-bindgen and wasmer. But we are looking to adopt the component model with wasmtime. The project uses Rust for the host and the wasm plugin. The structures defined use #[derive] attribute for implementing some traits.
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
With my wit file, is it possible to generate bindings with the derive attribute trait implementations? Or am I going about this the wrong way?
You can use with
to specify custom types (as long as they have the correct fields), and then derive what you need. I have an example here but I don't know if there are any "official" examples/tutorials/explanations on how to use the with
attribute.
Are you asking about host or guest bindings? For guest bindings, wit-bindgen has a additional_derives
option that would cover Clone
and PartialEq
.
It might also work for serde traits, but only if you don't need any other #[serde(...)]
attributes
https://serde.rs/remote-derive.html might be applicable here
Karel Hrkal (kajacx) said:
You can use
with
to specify custom types (as long as they have the correct fields), and then derive what you need. I have an example here but I don't know if there are any "official" examples/tutorials/explanations on how to use thewith
attribute.
Sorry for the late reply, but thank you for this! I see your example uses it on the guest side.. could I do this on the host side too?
I seem to get several trait bounds for wasmtime::component::<x> not satisfied errors for my types referenced using the with
attribute on the host side. Works fine on the guest side though.
Last updated: Dec 23 2024 at 13:07 UTC