Closed Nemo157 closed 4 years ago
I'm looking at this, and i'm looking at the macro_rules!
code, and i'm not sure how to make this change happen.
As far as I can tell, there's no way for the macro_rules!
to figure out what type (in terms of array length) the output is desired to be.
So we'd have to make a default, and then use a loop to push the element over and over or something? Does that sound right? Does that sound good?
Yeah, I think the implementation would have to end up being something like that (or iter::repeat($el).count($count).collect()
or similar); and then rely on the optimizer to turn that into just a memset
.
I'm worried that the collect wouldn't know what to type infer to any more.
I'd generally prefer a limited macro use that always gives correct type inference without extra info over a macro that does extra fancy stuff but you have to type annotate.
Yeah, checked just now,
($elem:expr; $n:expr) => {
//$crate::ArrayVec::from([$elem; $n])
::core::iter::repeat($elem).take($n).collect()
};
this makes the type inference fail all over.
EDIT: take, not count, but it's still an inference failure
currently fails with:
but using
tiny_vec![1.1, 1.1, 1.1]
in the same location works, also should be supported:And should check the error message for this to make sure it's still good: