Description
There should be some built-in syntax to create dynamically create vector values (both mutable and immutable) of a given size. Creating large contiguous arrays is a commonplace operation in low-level programming, and users should not have to use a library function or macro to do it. The syntax used in the following examples is not optimal for a few reasons, but illustrates the point.
For example, to create a vector of zeroes that is 20 elements long, you could use the single expressions:
@[0, ...20];
@[mut 0, ...20];
The following function would create a vector that is count
elements long, and every element has value t
:
fn mk_buffer<T: Copy>(count: uint, t: T) -> ~[T] {
return ~[t, ...count]
}
This syntax could support interleaving of multiple values as well. The following function would create a vector that is count
elements long, which alternates between the values t1
and t2
:
fn mk_alternating_buffer<T: Copy>(count: uint, t1: T, t2: T) ⟶ ~[T] {
return ~[t1, t2, ...count];
}