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.witfile and usewasmtime::component::bindgento 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-valueis generated aspub 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>; } }
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.witfile and usewasmtime::component::bindgento 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-valueis generated aspub 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>; } }
alexcrichton commented on issue #12134:
Does this example help answer your question?
ybbh commented on issue #12134:
Does this example help answer your question?
It solved my problem. Thank you very much.
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.witfile and usewasmtime::component::bindgento 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-valueis generated aspub 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