We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 397f33f commit e4af1caCopy full SHA for e4af1ca
src/libcore/vec.rs
@@ -323,6 +323,11 @@ fn shift<T: copy>(&v: [const T]) -> T {
323
ret e;
324
}
325
326
+#[doc = "Prepend an element to a vector"]
327
+fn unshift<T: copy>(&v: [const T], +t: T) {
328
+ v = [const t] + v;
329
+}
330
+
331
#[doc = "Remove the last element from a vector and return it"]
332
fn pop<T>(&v: [const T]) -> T unsafe {
333
let ln = len(v);
@@ -1734,6 +1739,13 @@ mod tests {
1734
1739
let addr_imm = unsafe::to_ptr(x_imm);
1735
1740
assert addr == addr_imm;
1736
1741
1742
1743
+ #[test]
1744
+ fn test_unshift() {
1745
+ let x = [1, 2, 3];
1746
+ unshift(x, 0);
1747
+ assert x == [0, 1, 2, 3];
1748
+ }
1737
1749
1738
1750
1751
// Local Variables:
0 commit comments