bytecodealliance / bytecodealliance/wit-bindgen

Support generics in generated `export!` macro in Rust

Open
#1,564 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
1.5k
Forks
286
Avg merge
6h 32m
Merged PRs (30d)
19

Description

The `wit_bindgen::generate!` macro generates a `export!` macro which has the following syntax supported:
```
($ty:ident) => ...;
($ty:ident with_types_in $($path_to_types_root:tt)*) => ...;
```
Since `$ty` is an `ident` only, it means I'm unable to pass in a path or type with generics, which is quite limiting.

My use case is something like this:
```rust
#[macro_export]
macro_rules! export_projection {
($ty:path) => {
$crate::runtime::projection::export!(
$crate::runtime::projection::Projection<$ty> with_types_in $crate::runtime::projection
);
};
}
pub struct Projection(PhantomData);

pub struct ProjectionState {
inner: RefCell,
}

impl Guest for Projection {
type ProjectionState = ProjectionState;
}

impl GuestProjectionState for ProjectionState {
...
}
```
But with the export! macro only accepting an `ident`, it becomes problematic.

I've experimented with simply changing wit_bindgen to use `path` instead of `ident`, which seems to work no problem. The only issue is `with_types_in` isn't supported here, so it needs to be changed to something like `$ty => $path_to_types_root`.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.