-
-
Notifications
You must be signed in to change notification settings - Fork 14.2k
Closed
Labels
A-syntaxextArea: Syntax extensionsArea: Syntax extensions
Description
This would allow http://static.rust-lang.org/doc/master/std/macros/macro.vec.html to use Vec::with_capacity to avoid unnecessary reallocations of the vector.
I'll be happy to take this on but I'm not entirely sure what a good syntax for this would be. I was thinking of:
macro_rules! vec(
($($e:expr),*) => ({
// leading _ to allow empty construction without a warning.
let mut _temp = ::std::vec_ng::Vec::with_capacity(#($e));
$(_temp.push($e);)*
_temp
})
)Since the individual elements in a multiplicative pattern can contain an arbitrary tree of expressions, # would recursively count all the elements that would expand to a specific $identifier.
Metadata
Metadata
Assignees
Labels
A-syntaxextArea: Syntax extensionsArea: Syntax extensions