File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change 1
1
---
2
- refs/heads/master: 3246723bf79ffc20e91936440cebc71ddcfd0a66
2
+ refs/heads/master: 5cf99e02b5f430812e8bce64bcf55c2194ace3ca
3
3
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4
4
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
5
5
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf
Original file line number Diff line number Diff line change @@ -396,6 +396,15 @@ fn shift<T>(&v: [T]) -> T {
396
396
}
397
397
}
398
398
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
+
399
408
#[ doc = "Remove the last element from a vector and return it" ]
400
409
fn pop < T > ( & v : [ const T ] ) -> T unsafe {
401
410
let ln = len ( v ) ;
@@ -2197,6 +2206,13 @@ mod tests {
2197
2206
assert addr == addr_imm;
2198
2207
}
2199
2208
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
+
2200
2216
#[ test]
2201
2217
fn test_capacity ( ) {
2202
2218
let mut v = [ 0u64 ] ;
You can’t perform that action at this time.
0 commit comments