Skip to content

feat(rust)!: use path in generated export! macro instead of ident#1566

Open
tqwewe wants to merge 2 commits intobytecodealliance:mainfrom
tqwewe:export-path
Open

feat(rust)!: use path in generated export! macro instead of ident#1566
tqwewe wants to merge 2 commits intobytecodealliance:mainfrom
tqwewe:export-path

Conversation

@tqwewe
Copy link

@tqwewe tqwewe commented Mar 13, 2026

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.

Closes #1564

@tqwewe tqwewe changed the title feat(path)!: use path in generated export! macro instead of ident feat(rust)!: use path in generated export! macro instead of ident Mar 13, 2026
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.
@alexcrichton
Copy link
Member

Thanks! Personally though I think that this'd need to be bikeshed a bit since the syntax here is pretty odd. I'm not sure if the restrictions on tokens after path are different than ty, so that may also be an option? I'd like to have this flow a bit more naturally though so if reading a macro invocation it's a bit more obvious as opposed to just having a stray comma somewhere in there.

I'll also note that there's a workaround today (I think) but I also agree it'd be best to not need a workaround, so that's just for a temporary state of affairs.

@tqwewe
Copy link
Author

tqwewe commented Mar 14, 2026

Yeah I actually initially used the syntax $ty => $path_to_types_root instead of $ty, with_types_in $path_to_types_root, but wanted to stick as close to the existing API as I could.

I agree the API is a bit weird. Not sure of any better alternatives than just =>.

I'm not sure if the restrictions on tokens after path are different than ty

I think I had the same issue when I initially tried ty.

@alexcrichton
Copy link
Member

Perhaps we could take a leaf out of Wasmtime's book? Something like:

generate!(MyType);
generate!(()); // uses `$t:ty` for this
generate!({
    ty: MyType,
    with_types_in: some::other::module,
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support generics in generated export! macro in Rust

2 participants