Skip to content

Commit e4af1ca

Browse files
committed
core: Add vec::unshift
1 parent 397f33f commit e4af1ca

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/libcore/vec.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,11 @@ fn shift<T: copy>(&v: [const T]) -> T {
323323
ret e;
324324
}
325325

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+
326331
#[doc = "Remove the last element from a vector and return it"]
327332
fn pop<T>(&v: [const T]) -> T unsafe {
328333
let ln = len(v);
@@ -1734,6 +1739,13 @@ mod tests {
17341739
let addr_imm = unsafe::to_ptr(x_imm);
17351740
assert addr == addr_imm;
17361741
}
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+
}
17371749
}
17381750

17391751
// Local Variables:

0 commit comments

Comments
 (0)