@@ -8,13 +8,13 @@ import ptr::addr_of;
8
8
9
9
#[ abi = "rust-intrinsic" ]
10
10
native mod rusti {
11
- fn vec_len < T > ( & & v: [ mutable? T ] ) -> uint ;
11
+ fn vec_len < T > ( & & v: [ const T ] ) -> uint ;
12
12
}
13
13
14
14
#[ abi = "cdecl" ]
15
15
native mod rustrt {
16
16
fn vec_reserve_shared < T > ( t : * sys:: type_desc ,
17
- & v: [ mutable? T ] ,
17
+ & v: [ const T ] ,
18
18
n : uint ) ;
19
19
fn vec_from_buf_shared < T > ( t : * sys:: type_desc ,
20
20
ptr : * T ,
@@ -34,7 +34,7 @@ Predicate: is_empty
34
34
35
35
Returns true if a vector contains no elements.
36
36
*/
37
- pure fn is_empty < T > ( v : [ mutable? T ] ) -> bool {
37
+ pure fn is_empty < T > ( v : [ const T ] ) -> bool {
38
38
// FIXME: This would be easier if we could just call len
39
39
for t: T in v { ret false ; }
40
40
ret true;
@@ -45,7 +45,7 @@ Predicate: is_not_empty
45
45
46
46
Returns true if a vector contains some elements.
47
47
*/
48
- pure fn is_not_empty < T > ( v : [ mutable? T ] ) -> bool { ret ! is_empty( v) ; }
48
+ pure fn is_not_empty < T > ( v : [ const T ] ) -> bool { ret ! is_empty( v) ; }
49
49
50
50
/*
51
51
Predicate: same_length
@@ -69,7 +69,7 @@ Parameters:
69
69
v - A vector
70
70
n - The number of elements to reserve space for
71
71
*/
72
- fn reserve < T > ( & v: [ mutable? T ] , n : uint ) {
72
+ fn reserve < T > ( & v: [ const T ] , n : uint ) {
73
73
rustrt:: vec_reserve_shared ( sys:: get_type_desc :: < T > ( ) , v, n) ;
74
74
}
75
75
@@ -78,7 +78,7 @@ Function: len
78
78
79
79
Returns the length of a vector
80
80
*/
81
- pure fn len < T > ( v : [ mutable? T ] ) -> uint { unchecked { rusti : : vec_len ( v) } }
81
+ pure fn len < T > ( v : [ const T ] ) -> uint { unchecked { rusti : : vec_len ( v) } }
82
82
83
83
/*
84
84
Function: init_fn
@@ -181,7 +181,7 @@ Returns the first element of a vector
181
181
Predicates:
182
182
<is_not_empty> (v)
183
183
*/
184
- fn head < T > ( v : [ mutable? T ] ) : is_not_empty( v ) -> T { ret v[ 0 ] ; }
184
+ fn head < T > ( v : [ const T ] ) : is_not_empty( v ) -> T { ret v[ 0 ] ; }
185
185
186
186
/*
187
187
Function: tail
@@ -191,7 +191,7 @@ Returns all but the first element of a vector
191
191
Predicates:
192
192
<is_not_empty> (v)
193
193
*/
194
- fn tail < T > ( v : [ mutable? T ] ) : is_not_empty( v ) -> [ T ] {
194
+ fn tail < T > ( v : [ const T ] ) : is_not_empty( v ) -> [ T ] {
195
195
ret slice ( v, 1 u, len ( v) ) ;
196
196
}
197
197
@@ -206,7 +206,7 @@ Returns all but the last elemnt of a vector
206
206
Preconditions:
207
207
`v` is not empty
208
208
*/
209
- fn init < T > ( v : [ mutable? T ] ) -> [ T ] {
209
+ fn init < T > ( v : [ const T ] ) -> [ T ] {
210
210
assert len( v) != 0 u;
211
211
slice ( v, 0 u, len ( v) - 1 u)
212
212
}
@@ -221,7 +221,7 @@ Returns:
221
221
An option containing the last element of `v` if `v` is not empty, or
222
222
none if `v` is empty.
223
223
*/
224
- fn last < T > ( v : [ mutable? T ] ) -> option:: t < T > {
224
+ fn last < T > ( v : [ const T ] ) -> option:: t < T > {
225
225
if len ( v) == 0 u { ret none; }
226
226
ret some( v[ len ( v) - 1 u] ) ;
227
227
}
@@ -234,7 +234,7 @@ Returns the last element of a non-empty vector `v`
234
234
Predicates:
235
235
<is_not_empty> (v)
236
236
*/
237
- fn last_total < T > ( v : [ mutable? T ] ) : is_not_empty( v ) -> T {
237
+ fn last_total < T > ( v : [ const T ] ) : is_not_empty( v ) -> T {
238
238
ret v[ len ( v) - 1 u] ;
239
239
}
240
240
@@ -243,7 +243,7 @@ Function: slice
243
243
244
244
Returns a copy of the elements from [`start`..`end`) from `v`.
245
245
*/
246
- fn slice < T > ( v : [ mutable? T ] , start : uint , end : uint ) -> [ T ] {
246
+ fn slice < T > ( v : [ const T ] , start : uint , end : uint ) -> [ T ] {
247
247
assert ( start <= end) ;
248
248
assert ( end <= len ( v) ) ;
249
249
let result = [ ] ;
@@ -259,7 +259,7 @@ Function: slice_mut
259
259
260
260
Returns a copy of the elements from [`start`..`end`) from `v`.
261
261
*/
262
- fn slice_mut < T > ( v : [ mutable? T ] , start : uint , end : uint ) -> [ mutable T ] {
262
+ fn slice_mut < T > ( v : [ const T ] , start : uint , end : uint ) -> [ mutable T ] {
263
263
assert ( start <= end) ;
264
264
assert ( end <= len ( v) ) ;
265
265
let result = [ mutable] ;
@@ -277,7 +277,7 @@ Function: shift
277
277
278
278
Removes the first element from a vector and return it
279
279
*/
280
- fn shift < T > ( & v: [ mutable? T ] ) -> T {
280
+ fn shift < T > ( & v: [ const T ] ) -> T {
281
281
let ln = len :: < T > ( v) ;
282
282
assert ( ln > 0 u) ;
283
283
let e = v[ 0 ] ;
@@ -291,7 +291,7 @@ Function: pop
291
291
292
292
Remove the last element from a vector and return it
293
293
*/
294
- fn pop < T > ( & v: [ mutable? T ] ) -> T {
294
+ fn pop < T > ( & v: [ const T ] ) -> T {
295
295
let ln = len ( v) ;
296
296
assert ( ln > 0 u) ;
297
297
ln -= 1 u;
@@ -323,7 +323,7 @@ fn grow<T>(&v: [T], n: uint, initval: T) {
323
323
}
324
324
325
325
// TODO: Remove me once we have slots.
326
- // FIXME: Can't grow take a [mutable? T]
326
+ // FIXME: Can't grow take a [const T]
327
327
/*
328
328
Function: grow_mut
329
329
@@ -384,7 +384,7 @@ Function: map
384
384
385
385
Apply a function to each element of a vector and return the results
386
386
*/
387
- fn map < T , U > ( f : block ( T ) -> U , v : [ mutable? T ] ) -> [ U ] {
387
+ fn map < T , U > ( f : block ( T ) -> U , v : [ const T ] ) -> [ U ] {
388
388
let result = [ ] ;
389
389
reserve ( result, len ( v) ) ;
390
390
for elem: T in v {
@@ -416,7 +416,7 @@ Apply a function to each element of a vector and return the results
416
416
If function `f` returns `none` then that element is excluded from
417
417
the resulting vector.
418
418
*/
419
- fn filter_map < T , U > ( f : block ( T ) -> option:: t < U > , v : [ mutable? T ] ) -> [ U ] {
419
+ fn filter_map < T , U > ( f : block ( T ) -> option:: t < U > , v : [ const T ] ) -> [ U ] {
420
420
let result = [ ] ;
421
421
for elem: T in v {
422
422
let elem2 = elem; // satisfies alias checker
@@ -437,7 +437,7 @@ holds.
437
437
Apply function `f` to each element of `v` and return a vector containing
438
438
only those elements for which `f` returned true.
439
439
*/
440
- fn filter < T > ( f : block ( T ) -> bool , v : [ mutable? T ] ) -> [ T ] {
440
+ fn filter < T > ( f : block ( T ) -> bool , v : [ const T ] ) -> [ T ] {
441
441
let result = [ ] ;
442
442
for elem: T in v {
443
443
let elem2 = elem; // satisfies alias checker
@@ -454,7 +454,7 @@ Function: concat
454
454
Concatenate a vector of vectors. Flattens a vector of vectors of T into
455
455
a single vector of T.
456
456
*/
457
- fn concat < T > ( v : [ mutable? [ mutable? T ] ] ) -> [ T ] {
457
+ fn concat < T > ( v: [ const [ const T ] ] ) -> [ T ] {
458
458
// FIXME: So much copying
459
459
let new: [ T ] = [ ] ;
460
460
for inner: [ T ] in v { new += inner; }
@@ -466,7 +466,7 @@ Function: foldl
466
466
467
467
Reduce a vector from left to right
468
468
*/
469
- fn foldl < T , U > ( p : block ( T , U ) -> T , z : T , v : [ mutable? U ] ) -> T {
469
+ fn foldl < T , U > ( p : block ( T , U ) -> T , z : T , v : [ const U ] ) -> T {
470
470
let accum = z;
471
471
iter ( v) { |elt|
472
472
accum = p ( accum, elt) ;
@@ -479,7 +479,7 @@ Function: foldr
479
479
480
480
Reduce a vector from right to left
481
481
*/
482
- fn foldr < T , U > ( p : block ( T , U ) -> U , z : U , v : [ mutable? T ] ) -> U {
482
+ fn foldr < T , U > ( p : block ( T , U ) -> U , z : U , v : [ const T ] ) -> U {
483
483
let accum = z;
484
484
riter ( v) { |elt|
485
485
accum = p ( elt, accum) ;
@@ -526,7 +526,7 @@ Function: count
526
526
527
527
Returns the number of elements that are equal to a given value
528
528
*/
529
- fn count < T > ( x : T , v : [ mutable? T ] ) -> uint {
529
+ fn count < T > ( x : T , v : [ const T ] ) -> uint {
530
530
let cnt = 0 u;
531
531
for elt: T in v { if x == elt { cnt += 1 u; } }
532
532
ret cnt;
@@ -646,7 +646,7 @@ Function: reversed
646
646
647
647
Returns a vector with the order of elements reversed
648
648
*/
649
- fn reversed < T > ( v : [ mutable? T ] ) -> [ T ] {
649
+ fn reversed < T > ( v : [ const T ] ) -> [ T ] {
650
650
let rs: [ T ] = [ ] ;
651
651
let i = len :: < T > ( v) ;
652
652
if i == 0 u { ret rs; } else { i -= 1 u; }
@@ -690,7 +690,7 @@ Iterates over vector `v` and, for each element, calls function `f` with the
690
690
element's value.
691
691
692
692
*/
693
- fn iter < T > ( v : [ mutable? T ] , f : block ( T ) ) {
693
+ fn iter < T > ( v : [ const T ] , f : block ( T ) ) {
694
694
iter2 ( v) { |_i, v| f ( v) }
695
695
}
696
696
@@ -702,7 +702,7 @@ Iterates over a vector's elements and indexes
702
702
Iterates over vector `v` and, for each element, calls function `f` with the
703
703
element's value and index.
704
704
*/
705
- fn iter2 < T > ( v : [ mutable? T ] , f : block ( uint , T ) ) {
705
+ fn iter2 < T > ( v : [ const T ] , f : block ( uint , T ) ) {
706
706
let i = 0 u;
707
707
for x in v { f ( i, x) ; i += 1 u; }
708
708
}
@@ -716,7 +716,7 @@ Iterates over vector `v` and, for each element, calls function `f` with the
716
716
element's value.
717
717
718
718
*/
719
- fn riter < T > ( v : [ mutable? T ] , f : block ( T ) ) {
719
+ fn riter < T > ( v : [ const T ] , f : block ( T ) ) {
720
720
riter2 ( v) { |_i, v| f ( v) }
721
721
}
722
722
@@ -728,7 +728,7 @@ Iterates over a vector's elements and indexes in reverse
728
728
Iterates over vector `v` and, for each element, calls function `f` with the
729
729
element's value and index.
730
730
*/
731
- fn riter2 < T > ( v : [ mutable? T ] , f : block ( uint , T ) ) {
731
+ fn riter2 < T > ( v : [ const T ] , f : block ( uint , T ) ) {
732
732
let i = len ( v) ;
733
733
while 0 u < i {
734
734
i -= 1 u;
@@ -746,7 +746,7 @@ is sorted then the permutations are lexicographically sorted).
746
746
The total number of permutations produced is `len(v)!`. If `v` contains
747
747
repeated elements, then some permutations are repeated.
748
748
*/
749
- fn permute < T > ( v : [ mutable? T ] , put : block ( [ T ] ) ) {
749
+ fn permute < T > ( v : [ const T ] , put : block ( [ T ] ) ) {
750
750
let ln = len ( v) ;
751
751
if ln == 0 u {
752
752
put ( [ ] ) ;
@@ -798,7 +798,7 @@ mod unsafe {
798
798
modifing its buffers, so it is up to the caller to ensure that
799
799
the vector is actually the specified size.
800
800
*/
801
- unsafe fn set_len < T > ( & v: [ mutable? T ] , new_len : uint ) {
801
+ unsafe fn set_len < T > ( & v: [ const T ] , new_len : uint ) {
802
802
let repr: * * vec_repr = :: unsafe:: reinterpret_cast ( addr_of ( v) ) ;
803
803
( * * repr) . fill = new_len * sys:: size_of :: < T > ( ) ;
804
804
}
@@ -814,7 +814,7 @@ mod unsafe {
814
814
Modifying the vector may cause its buffer to be reallocated, which
815
815
would also make any pointers to it invalid.
816
816
*/
817
- unsafe fn to_ptr < T > ( v : [ mutable? T ] ) -> * T {
817
+ unsafe fn to_ptr < T > ( v : [ const T ] ) -> * T {
818
818
let repr: * * vec_repr = :: unsafe:: reinterpret_cast ( addr_of ( v) ) ;
819
819
ret :: unsafe:: reinterpret_cast ( addr_of ( ( * * repr) . data ) ) ;
820
820
}
0 commit comments