statiolake / proconio-rs

Apache License 2.0
117 stars 6 forks source link

Allow type with more than one generic arg #47

Closed MiSawa closed 4 months ago

MiSawa commented 5 months ago

I noticed that we can't use generic types with two or more arguments for the @kind part of the input! macro. This is, IIUC, bacause the comma , that separates generic arguments is treated as a comma that separates fields in input! macro, and thus read_value! gets something like @kind Foo<Arg1.

To fix the issue, I had to special-case vec type [...] and tuple type (...) inside the input! macro and fall-through to ty instead of tt*, since once the whole [...]/(..) are matched to ty it can't be matched to [ tt* ] / ( tt* ) in read_value! macro, it seems to me. (see: https://doc.rust-lang.org/nightly/reference/macros-by-example.html#forwarding-a-matched-fragment )

Disclaimer: I'm noob at macros, and not 100% confident with the change. Please read the change with a skeptical eye :pray:

statiolake commented 4 months ago

Sorry for the late reply. It looks good to me. As far as I remember, the only reason I avoided using ty matcher is to specialize vectors [T; n] and tuples (T, U, ...), just as you explained. They seem to be correctly cared in the fix.

CI is failing but that's not related to this PR. I'll merge this and fix it later.

Thank you for the PR!