tinyvec
tinyvec copied to clipboard
array_vec! macro cannot work with tuple element
This expression tries to construct an ArrayVec
with element type (f32, f32)
but cannot compile:
let a: ArrayVec<[(f32,f32); 3]> = array_vec!((2.0, 2.0), (2.0, 2.0), (2.0, 2.0));
The error goes like:
expected type, found `2.0`
expected type
Meanwhile, the vec!
macro can handle this well.
The problem here is that array_vec! has several ways it can be invoked.
macro_rules! array_vec {
($array_type:ty => $($elem:expr),* $(,)?) => { ... };
($array_type:ty) => { ... };
($($elem:expr),*) => { ... };
($elem:expr; $n:expr) => { ... };
() => { ... };
}
Unfortunately, in this situation it seems to be doing a partial match on the 2nd case, ($array_type:ty) => { ... };
, which then fails because that's not actually what you wanted.
I don't think there's an easy fix here, because changing the ordering of the match arms can break other people's code instead.
I'll link this issue in the discord and perhaps a macro expert can swoop in and solve the problem.
In the mean time, array_vec!([(f32,f32); 3] => (2.0, 2.0), (2.0, 2.0), (2.0, 2.0))
is more verbose but does work how you want (playground example).