Stream: wasmtime

Topic: #[derive(ComponentType, Lower, Lift)] in wasmtime for enums


view this post on Zulip Div (Jun 18 2024 at 11:58):

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?

view this post on Zulip Div (Jun 18 2024 at 12:11):

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,

});

view this post on Zulip Joel Dice (Jun 18 2024 at 13:49):

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),
}

view this post on Zulip Div (Jun 25 2024 at 13:08):

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