Stream: git-wasmtime

Topic: wasmtime / issue #12134 [Question] WIT Resource types are...


view this post on Zulip Wasmtime GitHub notifications bot (Dec 07 2025 at 15:49):

ybbh opened issue #12134:

WIT Resource types are generated as empty enums by wasmtime::component::bindgen macro. How should I use the empty enums in my custom implementations? Any help would be appreciated.

I have a host.wit file and use wasmtime::component::bindgen to generate code for host bindings.

wasmtime::component::bindgen!("host" in "src/host_export/host.wit");

When I expand this bindgen! macro, I notice that resource types are generated as empty enums (for example, the resource type mu-dat-value is generated as pub enum MuDatValue {}).

How should I use it in my custom implementations? For instance, for the resource mu-dat-value, I want to implement a structure like:

custom implementation in host

impl HostMuDatValue for MyDatValue {
    fn from_i32(&mut self, value: i32) -> wasmtime::component::Resource<MuDatValue> {
       let value = MuDatValue::from_i32(value)
       todo!()
    }
}

host.wit

package host:binding;

world host {
    import  binding-interface;
}

interface binding-interface {
    resource mu-dat-value {
        from-i32 :static func(value: s32) -> mu-dat-value;
        from-i64 :static func(value: s64) -> mu-dat-value;
        from-f32 :static func(value: f32) -> mu-dat-value;
        from-f64 :static func(value: f64) -> mu-dat-value;
        from-string :static func(value: string) -> mu-dat-value;
        as-i32: func() -> option<s32>;
        as-i64: func() -> option<s64>;
        as-f32: func() -> option<f32>;
        as-f64: func() -> option<f64>;
        as-string: func() -> option<string>;
    }
}

view this post on Zulip Wasmtime GitHub notifications bot (Dec 07 2025 at 15:57):

ybbh edited issue #12134:

WIT Resource types are generated as empty enums by wasmtime::component::bindgen macro. How should I use the empty enums in my custom implementations? Any help would be appreciated.

I have a host.wit file and use wasmtime::component::bindgen to generate code for host bindings.

wasmtime::component::bindgen!("host" in "src/host_export/host.wit");

When I expand this bindgen! macro, I notice that resource types are generated as empty enums (for example, the resource type mu-dat-value is generated as pub enum MuDatValue {}).

How should I use it in my custom implementations? For instance, for the resource mu-dat-value, I want to implement a structure like:

custom implementation in host

impl HostMuDatValue for MyDatValue {
    fn from_i32(&mut self, value: i32) -> wasmtime::component::Resource<MuDatValue> {
       let value:MuDatValue = todo_something_like_from_i32(value)
       todo!()
    }
}

host.wit

package host:binding;

world host {
    import  binding-interface;
}

interface binding-interface {
    resource mu-dat-value {
        from-i32 :static func(value: s32) -> mu-dat-value;
        from-i64 :static func(value: s64) -> mu-dat-value;
        from-f32 :static func(value: f32) -> mu-dat-value;
        from-f64 :static func(value: f64) -> mu-dat-value;
        from-string :static func(value: string) -> mu-dat-value;
        as-i32: func() -> option<s32>;
        as-i64: func() -> option<s64>;
        as-f32: func() -> option<f32>;
        as-f64: func() -> option<f64>;
        as-string: func() -> option<string>;
    }
}

view this post on Zulip Wasmtime GitHub notifications bot (Dec 08 2025 at 14:37):

alexcrichton commented on issue #12134:

Does this example help answer your question?

view this post on Zulip Wasmtime GitHub notifications bot (Dec 09 2025 at 02:07):

ybbh commented on issue #12134:

Does this example help answer your question?

It solved my problem. Thank you very much.

view this post on Zulip Wasmtime GitHub notifications bot (Dec 09 2025 at 15:34):

alexcrichton closed issue #12134:

WIT Resource types are generated as empty enums by wasmtime::component::bindgen macro. How should I use the empty enums in my custom implementations? Any help would be appreciated.

I have a host.wit file and use wasmtime::component::bindgen to generate code for host bindings.

wasmtime::component::bindgen!("host" in "src/host_export/host.wit");

When I expand this bindgen! macro, I notice that resource types are generated as empty enums (for example, the resource type mu-dat-value is generated as pub enum MuDatValue {}).

How should I use it in my custom implementations? For instance, for the resource mu-dat-value, I want to implement a structure like:

custom implementation in host

impl HostMuDatValue for MyDatValue {
    fn from_i32(&mut self, value: i32) -> wasmtime::component::Resource<MuDatValue> {
       let value:MuDatValue = todo_something_like_from_i32(value)
       todo!()
    }
}

host.wit

package host:binding;

world host {
    import  binding-interface;
}

interface binding-interface {
    resource mu-dat-value {
        from-i32 :static func(value: s32) -> mu-dat-value;
        from-i64 :static func(value: s64) -> mu-dat-value;
        from-f32 :static func(value: f32) -> mu-dat-value;
        from-f64 :static func(value: f64) -> mu-dat-value;
        from-string :static func(value: string) -> mu-dat-value;
        as-i32: func() -> option<s32>;
        as-i64: func() -> option<s64>;
        as-f32: func() -> option<f32>;
        as-f64: func() -> option<f64>;
        as-string: func() -> option<string>;
    }
}


Last updated: Dec 13 2025 at 19:03 UTC