Skip to content

Commit 324e248

Browse files
committed
---
yaml --- r: 13655 b: refs/heads/master c: 5cf99e0 h: refs/heads/master i: 13653: 5065bec 13651: eb9ab43 13647: 4ef7e4f v: v3
1 parent 9e37c47 commit 324e248

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 3246723bf79ffc20e91936440cebc71ddcfd0a66
2+
refs/heads/master: 5cf99e02b5f430812e8bce64bcf55c2194ace3ca
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

trunk/src/libcore/vec.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,15 @@ fn shift<T>(&v: [T]) -> T {
396396
}
397397
}
398398

399+
#[doc = "Prepend an element to the vector"]
400+
fn unshift<T>(&v: [T], +x: T) {
401+
let mut vv = [x];
402+
v <-> vv;
403+
while len(vv) > 0 {
404+
push(v, shift(vv));
405+
}
406+
}
407+
399408
#[doc = "Remove the last element from a vector and return it"]
400409
fn pop<T>(&v: [const T]) -> T unsafe {
401410
let ln = len(v);
@@ -2197,6 +2206,13 @@ mod tests {
21972206
assert addr == addr_imm;
21982207
}
21992208

2209+
#[test]
2210+
fn test_unshift() {
2211+
let mut x = [1, 2, 3];
2212+
unshift(x, 0);
2213+
assert x == [0, 1, 2, 3];
2214+
}
2215+
22002216
#[test]
22012217
fn test_capacity() {
22022218
let mut v = [0u64];

0 commit comments

Comments
 (0)