Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds the special
Vararg!
"macro" (really just a marker) which allows the creation of variadic methods, i.e. methods that take a variable number of arguments. The "vararg" variable collects the optional arguments in aVararg<T>
type, which implementsIntoIterator
as a value, a reference and a mutable reference, as well asIndex
andIndexMut
forSliceIndex<[T]>
(making it sort of like a fixed-length vector)Example:
This is a pretty silly implementation, since it just adds a method for each possible number of extra arguments, e.g. the
MAX
function above has 13 methods, one for zero, another for one, another for two.. until twelve. Since method can only have up to 12 arguments currently, the total number of methods is (13 - the number of required arguments). This will have to do until Variadic Generics are implemented. (rust-lang/rfcs#376, rust-lang/rfcs#1935)Also of note is the interaction between varargs and other methods.