Pre-RFC: Static Function Argument Unpacking

Any type can be used in a range literal. The RangeBounds trait isn't for types which can be used in a range, it's implemented for the various range types themselves, to allow the definition of generic functions accepting any of the range types.

..expr is always a valid expression, meaning exactly RangeTo { end: expr }.

I am sympathetic to that this seems to be the natural syntax, given that ..base is used for the "splat" in FRU syntax, and it's not great to have both .. and ... potentially valid in the same position meaning different things, but using ..expr for argument unpacking seems very unlikely to work.

The most complete variadics design sketch currently uses ...expr to unpack.

Function parameter names are currently not considered part of the stable API surface in Rust. Making them part of stable API with no code change is a nonstarter.

Also a notable case is C++, which also uses expr... for pack expansion. A more full survey of variadics is fairly evenly split between prefix and postfix indication of an unpack.

There actually is a pseudo-variadic syntax used for docs only, e.g. (T₁, T₂, …, Tₙ). This uses , U+2026 Horizontal Ellipsis Unicode Character, instead of an ASCII approximation.


I could nitpick further but it wouldn't be particularly constructive. Unpacking doesn't exist yet not because nobody's thought about adding it, but because it's much more involved than it seems at first glance.

7 Likes