Skip to content

Commit ddd50ed

Browse files
committed
---
yaml --- r: 10675 b: refs/heads/snap-stage3 c: 5cf99e0 h: refs/heads/master i: 10673: 7d88315 10671: 9400c74 v: v3
1 parent 8482e50 commit ddd50ed

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,6 +1,6 @@
11
---
22
refs/heads/master: 2898dcc5d97da9427ac367542382b6239d9c0bbf
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 3246723bf79ffc20e91936440cebc71ddcfd0a66
4+
refs/heads/snap-stage3: 5cf99e02b5f430812e8bce64bcf55c2194ace3ca
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/snap-stage3/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)