fc6b7c8b38
Long lines were fixed in a very crude way, as I'll be following up with another reformat in a bit.
29 lines
735 B
Rust
29 lines
735 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
|
|
}
|