File tree Expand file tree Collapse file tree 3 files changed +25
-1
lines changed Expand file tree Collapse file tree 3 files changed +25
-1
lines changed Original file line number Diff line number Diff line change 1
1
---
2
- refs/heads/master: 6b1c60d312ef420c84a61bb80b8c1cc9434654f7
2
+ refs/heads/master: 8e54e74be4254ac374b5496888d14987dede0008
Original file line number Diff line number Diff line change @@ -300,6 +300,15 @@ fn pop<copy T>(&v: [const T]) -> T {
300
300
ret e;
301
301
}
302
302
303
+ /*
304
+ Function: push
305
+
306
+ Append an element to a vector and return it
307
+ */
308
+ fn push < copy T > ( & v: [ T ] , initval : T ) {
309
+ grow ( v, 1 u, initval)
310
+ }
311
+
303
312
// TODO: More.
304
313
305
314
Original file line number Diff line number Diff line change @@ -170,6 +170,21 @@ fn test_pop() {
170
170
assert ( e == 5 ) ;
171
171
}
172
172
173
+ #[ test]
174
+ fn test_push ( ) {
175
+ // Test on-stack push().
176
+ let v = [ ] ;
177
+ vec:: push ( v, 1 ) ;
178
+ assert ( vec:: len ( v) == 1 u) ;
179
+ assert ( v[ 0 ] == 1 ) ;
180
+
181
+ // Test on-heap push().
182
+ vec:: push ( v, 2 ) ;
183
+ assert ( vec:: len ( v) == 2 u) ;
184
+ assert ( v[ 0 ] == 1 ) ;
185
+ assert ( v[ 1 ] == 2 ) ;
186
+ }
187
+
173
188
#[ test]
174
189
fn test_grow ( ) {
175
190
// Test on-stack grow().
You can’t perform that action at this time.
0 commit comments