From 8b93e9ec6dcd5e294fba9761824edec69637948c Mon Sep 17 00:00:00 2001 From: Ari Seyhun Date: Fri, 13 Mar 2026 16:32:58 +1100 Subject: [PATCH 1/5] feat(rust)!: use path in generated `export!` macro instead of `ident` Changes the generated `export!` macro to accept a `$ty:path` instead of `$ty:ident` for more flexibility. Requires the `with_types_in` separator to be changed to `, with_types_in`, since a `path` cannot be followed by an ident in macros. --- crates/guest-rust/src/lib.rs | 4 ++-- crates/rust/src/interface.rs | 2 +- crates/rust/src/lib.rs | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/guest-rust/src/lib.rs b/crates/guest-rust/src/lib.rs index a2a35d5b9..0c57f9ff0 100644 --- a/crates/guest-rust/src/lib.rs +++ b/crates/guest-rust/src/lib.rs @@ -574,7 +574,7 @@ extern crate std; /// # // ... /// # } /// # -/// export!(MyComponent with_types_in self); +/// export!(MyComponent, with_types_in self); /// # /// # fn main() {} /// ``` @@ -607,7 +607,7 @@ extern crate std; /// # // ... /// # } /// # -/// bindings::export!(MyComponent with_types_in bindings); +/// bindings::export!(MyComponent, with_types_in bindings); /// # /// # fn main() {} /// ``` diff --git a/crates/rust/src/interface.rs b/crates/rust/src/interface.rs index 4f4f00471..eb059a1b6 100644 --- a/crates/rust/src/interface.rs +++ b/crates/rust/src/interface.rs @@ -277,7 +277,7 @@ fn _resource_rep(handle: u32) -> *mut u8 #[doc(hidden)] {macro_export} macro_rules! {macro_name} {{ - ($ty:ident with_types_in $($path_to_types:tt)*) => (const _: () = {{ + ($ty:path, with_types_in $($path_to_types:tt)*) => (const _: () = {{ " ); diff --git a/crates/rust/src/lib.rs b/crates/rust/src/lib.rs index 3df749648..93b52a740 100644 --- a/crates/rust/src/lib.rs +++ b/crates/rust/src/lib.rs @@ -875,8 +875,8 @@ impl As{upcase} for {to_convert} {{ #[doc(hidden)] {macro_export} macro_rules! __export_{world_name}_impl {{ - ($ty:ident) => ({default_bindings_module}::{export_macro_name}!($ty with_types_in {default_bindings_module});); - ($ty:ident with_types_in $($path_to_types_root:tt)*) => ("# + ($ty:path) => ({default_bindings_module}::{export_macro_name}!($ty => {default_bindings_module});); + ($ty:path, with_types_in $($path_to_types_root:tt)*) => ("# ); for (name, path_to_types) in self.export_macros.iter() { let mut path = "$($path_to_types_root)*".to_string(); @@ -884,7 +884,7 @@ macro_rules! __export_{world_name}_impl {{ path.push_str("::"); path.push_str(path_to_types) } - uwriteln!(self.src, "{path}::{name}!($ty with_types_in {path});"); + uwriteln!(self.src, "{path}::{name}!($ty, with_types_in {path});"); } // See comments in `finish` for why this conditionally happens here. From f2086a5a4c482ec02ea872170ae81f1f5992f542 Mon Sep 17 00:00:00 2001 From: Ari Seyhun Date: Fri, 13 Mar 2026 18:32:26 +1100 Subject: [PATCH 2/5] fix(rust): export world macro --- crates/rust/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/rust/src/lib.rs b/crates/rust/src/lib.rs index 93b52a740..2045e3529 100644 --- a/crates/rust/src/lib.rs +++ b/crates/rust/src/lib.rs @@ -875,7 +875,7 @@ impl As{upcase} for {to_convert} {{ #[doc(hidden)] {macro_export} macro_rules! __export_{world_name}_impl {{ - ($ty:path) => ({default_bindings_module}::{export_macro_name}!($ty => {default_bindings_module});); + ($ty:path) => ({default_bindings_module}::{export_macro_name}!($ty, with_types_in {default_bindings_module});); ($ty:path, with_types_in $($path_to_types_root:tt)*) => ("# ); for (name, path_to_types) in self.export_macros.iter() { From 68da25b7938f6591e2fff13959a57e32c4e34518 Mon Sep 17 00:00:00 2001 From: Ari Seyhun Date: Wed, 8 Apr 2026 15:31:33 +1000 Subject: [PATCH 3/5] use object literal syntax with export! macro for with_types_in --- crates/guest-rust/src/lib.rs | 4 ++-- crates/rust/src/interface.rs | 2 +- crates/rust/src/lib.rs | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/guest-rust/src/lib.rs b/crates/guest-rust/src/lib.rs index 0c57f9ff0..767346cc2 100644 --- a/crates/guest-rust/src/lib.rs +++ b/crates/guest-rust/src/lib.rs @@ -574,7 +574,7 @@ extern crate std; /// # // ... /// # } /// # -/// export!(MyComponent, with_types_in self); +/// export!({ ty: MyComponent, with_types_in: self }); /// # /// # fn main() {} /// ``` @@ -607,7 +607,7 @@ extern crate std; /// # // ... /// # } /// # -/// bindings::export!(MyComponent, with_types_in bindings); +/// bindings::export!({ ty: MyComponent, with_types_in: bindings }); /// # /// # fn main() {} /// ``` diff --git a/crates/rust/src/interface.rs b/crates/rust/src/interface.rs index eb059a1b6..19724b5dc 100644 --- a/crates/rust/src/interface.rs +++ b/crates/rust/src/interface.rs @@ -277,7 +277,7 @@ fn _resource_rep(handle: u32) -> *mut u8 #[doc(hidden)] {macro_export} macro_rules! {macro_name} {{ - ($ty:path, with_types_in $($path_to_types:tt)*) => (const _: () = {{ + ({{ ty: $ty:path, with_types_in: $path_to_types:path $(,)? }}) => (const _: () = {{ " ); diff --git a/crates/rust/src/lib.rs b/crates/rust/src/lib.rs index 2045e3529..a00d95b04 100644 --- a/crates/rust/src/lib.rs +++ b/crates/rust/src/lib.rs @@ -875,8 +875,8 @@ impl As{upcase} for {to_convert} {{ #[doc(hidden)] {macro_export} macro_rules! __export_{world_name}_impl {{ - ($ty:path) => ({default_bindings_module}::{export_macro_name}!($ty, with_types_in {default_bindings_module});); - ($ty:path, with_types_in $($path_to_types_root:tt)*) => ("# + ($ty:path) => ({default_bindings_module}::{export_macro_name}!({{ ty: $ty, with_types_in: {default_bindings_module} }});); + ({{ $ty:path $(, $(with_types_in: $path_to_types:path $(,)?)?)? }}) => ("# ); for (name, path_to_types) in self.export_macros.iter() { let mut path = "$($path_to_types_root)*".to_string(); @@ -884,7 +884,7 @@ macro_rules! __export_{world_name}_impl {{ path.push_str("::"); path.push_str(path_to_types) } - uwriteln!(self.src, "{path}::{name}!($ty, with_types_in {path});"); + uwriteln!(self.src, "{path}::{name}!({{ ty: $ty, with_types_in: {path} }});"); } // See comments in `finish` for why this conditionally happens here. From 6fffefb4405d3a2cd5b5271e9efd5a0f7ca7da46 Mon Sep 17 00:00:00 2001 From: Ari Seyhun Date: Wed, 8 Apr 2026 15:34:38 +1000 Subject: [PATCH 4/5] fix formatting --- crates/rust/src/lib.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/rust/src/lib.rs b/crates/rust/src/lib.rs index a00d95b04..4c51010a9 100644 --- a/crates/rust/src/lib.rs +++ b/crates/rust/src/lib.rs @@ -884,7 +884,10 @@ macro_rules! __export_{world_name}_impl {{ path.push_str("::"); path.push_str(path_to_types) } - uwriteln!(self.src, "{path}::{name}!({{ ty: $ty, with_types_in: {path} }});"); + uwriteln!( + self.src, + "{path}::{name}!({{ ty: $ty, with_types_in: {path} }});" + ); } // See comments in `finish` for why this conditionally happens here. From a5748a22cd65f7e413b9b103260e68483371b0fc Mon Sep 17 00:00:00 2001 From: Ari Seyhun Date: Wed, 8 Apr 2026 16:00:27 +1000 Subject: [PATCH 5/5] fix export macro syntax --- crates/rust/src/interface.rs | 2 +- crates/rust/src/lib.rs | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/rust/src/interface.rs b/crates/rust/src/interface.rs index 19724b5dc..2cf432607 100644 --- a/crates/rust/src/interface.rs +++ b/crates/rust/src/interface.rs @@ -277,7 +277,7 @@ fn _resource_rep(handle: u32) -> *mut u8 #[doc(hidden)] {macro_export} macro_rules! {macro_name} {{ - ({{ ty: $ty:path, with_types_in: $path_to_types:path $(,)? }}) => (const _: () = {{ + ({{ ty: $ty:path, with_types_in: $($path_to_types:tt)* }}) => (const _: () = {{ " ); diff --git a/crates/rust/src/lib.rs b/crates/rust/src/lib.rs index 4c51010a9..4599d071d 100644 --- a/crates/rust/src/lib.rs +++ b/crates/rust/src/lib.rs @@ -876,10 +876,12 @@ impl As{upcase} for {to_convert} {{ {macro_export} macro_rules! __export_{world_name}_impl {{ ($ty:path) => ({default_bindings_module}::{export_macro_name}!({{ ty: $ty, with_types_in: {default_bindings_module} }});); - ({{ $ty:path $(, $(with_types_in: $path_to_types:path $(,)?)?)? }}) => ("# + ({{ ty: $ty:path $(,)? }}) => ({default_bindings_module}::{export_macro_name}!({{ ty: $ty, with_types_in: {default_bindings_module} }});); + ({{ ty: $ty:path, with_types_in: $($path_to_types:tt)+, }}) => ({default_bindings_module}::{export_macro_name}!({{ ty: $ty, with_types_in: $($path_to_types)* }});); + ({{ ty: $ty:path, with_types_in: $($path_to_types:tt)+ }}) => ("# ); for (name, path_to_types) in self.export_macros.iter() { - let mut path = "$($path_to_types_root)*".to_string(); + let mut path = "$($path_to_types)*".to_string(); if !path_to_types.is_empty() { path.push_str("::"); path.push_str(path_to_types)