For my wasm components, on the rust host, I have types that I am using #[derive(ComponentType, Lower, Lift)] on to be able to pass to web assembly. But, I am have case issue with only the enums/variant type.
For example in the wit file, if I have
variant window-expression {
time-based(time-based-sliding-window-expression-D-T-O),
count-based(count-based-sliding-window-expression),
}
and the rust type on host
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, ComponentType, Lower, Lift)]
#[component(variant)]
pub enum WindowExpression {
TimeBased(TimeBasedSlidingWindowExpressionDTO),
CountBased(CountBasedSlidingWindowExpression),
}
I get a type mismatch error: expected variant case named TimeBased, found time-based
I'm not sure how to debug where it is creating the time-based variant. Any idea why this might be happening?
also, on the host
bindgen!({
world: "join",
path: "wit/operators.wit",
with: {
"component:operators/types": crate::interface_types::types, // this is for the rust types with enum above
},
async: true,
});
I believe you need to add #[component(name = "...")]
attributes, e.g.:
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, ComponentType, Lower, Lift)]
#[component(variant)]
pub enum WindowExpression {
#[component(name = "time-based")]
TimeBased(TimeBasedSlidingWindowExpressionDTO),
#[component(name = "count-based")]
CountBased(CountBasedSlidingWindowExpression),
}
Joel Dice said:
I believe you need to add
#[component(name = "...")]
attributes, e.g.:#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, ComponentType, Lower, Lift)] #[component(variant)] pub enum WindowExpression { #[component(name = "time-based")] TimeBased(TimeBasedSlidingWindowExpressionDTO), #[component(name = "count-based")] CountBased(CountBasedSlidingWindowExpression), }
works, thank you!
Last updated: Nov 22 2024 at 16:03 UTC