This is a simple wrapper around grow for the common
case of pushing a value on the end of a vector.
ret e;
}
+/*
+Function: push
+
+Append an element to a vector and return it
+*/
+fn push<copy T>(&v: [T], initval: T) {
+ grow(v, 1u, initval)
+}
+
// TODO: More.
assert (e == 5);
}
+#[test]
+fn test_push() {
+ // Test on-stack push().
+ let v = [];
+ vec::push(v, 1);
+ assert (vec::len(v) == 1u);
+ assert (v[0] == 1);
+
+ // Test on-heap push().
+ vec::push(v, 2);
+ assert (vec::len(v) == 2u);
+ assert (v[0] == 1);
+ assert (v[1] == 2);
+}
+
#[test]
fn test_grow() {
// Test on-stack grow().