rust/src/test/run-pass/interior-vec.rs
Marijn Haverbeke c9c5ee252a Implement non-internal ivecs
Vectors are now similar to our old, pre-internal vectors, except that
they are uniquely owned, not refcounted.

Their name should probably change too, then. I've renamed them to vec
in the runtime, will do so throughout the compiler later.
2011-08-29 09:07:53 +02:00

29 lines
736 B
Rust

import rusti::vec_len;
native "rust-intrinsic" mod rusti {
fn vec_len<T>(v: &[T]) -> uint;
}
fn main() {
let v: [int] = [];
assert (vec_len(v) == 0u); // zero-length
let x = [1, 2];
assert (vec_len(x) == 2u); // on stack
let y = [1, 2, 3, 4, 5];
assert (vec_len(y) == 5u); // on heap
v += [];
assert (vec_len(v) == 0u); // zero-length append
x += [3];
assert (vec_len(x) == 3u); // on-stack append
y += [6, 7, 8, 9];
assert (vec_len(y) == 9u); // on-heap append
let vv = v + v;
assert (vec_len(vv) == 0u); // zero-length add
let xx = x + [4];
assert (vec_len(xx) == 4u); // on-stack add
let yy = y + [10, 11];
assert (vec_len(yy) == 11u); // on-heap add
}