@@ -10,14 +10,14 @@ native "rust-intrinsic" mod rusti {
10
10
}
11
11
12
12
native "rust" mod rustrt {
13
- fn ivec_reserve[ T ] ( & mutable T [ ] v, uint n) ;
13
+ fn ivec_reserve[ T ] ( & mutable T [ mutable? ] v, uint n) ;
14
14
fn ivec_on_heap[ T ] ( & T [ ] v) -> bool;
15
15
fn ivec_to_ptr[ T ] ( & T [ ] v) -> * T ;
16
- fn ivec_copy_from_buf[ T ] ( & mutable T [ ] v, * T ptr, uint count) ;
16
+ fn ivec_copy_from_buf[ T ] ( & mutable T [ mutable? ] v, * T ptr, uint count) ;
17
17
}
18
18
19
19
/// Reserves space for `n` elements in the given vector.
20
- fn reserve[ T ] ( & mutable T [ ] v, uint n) {
20
+ fn reserve[ T ] ( & mutable T [ mutable? ] v, uint n) {
21
21
rustrt:: ivec_reserve ( v, n) ;
22
22
}
23
23
@@ -43,6 +43,69 @@ fn init_fn[T](&init_op[T] op, uint n_elts) -> T[] {
43
43
ret v;
44
44
}
45
45
46
+ // TODO: Remove me once we have slots.
47
+ fn init_fn_mut[ T ] ( & init_op[ T ] op, uint n_elts) -> T [ mutable] {
48
+ auto v = ~[ mutable] ;
49
+ reserve ( v, n_elts) ;
50
+ let uint i = 0 u;
51
+ while ( i < n_elts) { v += ~[ mutable op( i) ] ; i += 1 u; }
52
+ ret v;
53
+ }
54
+
55
+ fn init_elt[ T ] ( & T t, uint n_elts) -> T [ ] {
56
+ auto v = ~[ ] ;
57
+ reserve ( v, n_elts) ;
58
+ let uint i = 0 u;
59
+ while ( i < n_elts) { v += ~[ t] ; i += 1 u; }
60
+ ret v;
61
+ }
62
+
63
+ // TODO: Remove me once we have slots.
64
+ fn init_elt_mut[ T ] ( & T t, uint n_elts) -> T [ mutable] {
65
+ auto v = ~[ mutable] ;
66
+ reserve ( v, n_elts) ;
67
+ let uint i = 0 u;
68
+ while ( i < n_elts) { v += ~[ mutable t] ; i += 1 u; }
69
+ ret v;
70
+ }
71
+
72
+
73
+ // Accessors
74
+
75
+ /// Returns the last element of `v`.
76
+ fn last[ T ] ( & T [ mutable?] v) -> option:: t[ T ] {
77
+ if ( len ( v) == 0 u) { ret none; }
78
+ ret some( v. ( len ( v) - 1 u) ) ;
79
+ }
80
+
81
+ /// Returns a copy of the elements from [`start`..`end`) from `v`.
82
+ fn slice[ T ] ( & T [ mutable?] v, uint start, uint end) -> T [ ] {
83
+ assert ( start <= end) ;
84
+ assert ( end <= len ( v) ) ;
85
+ auto result = ~[ ] ;
86
+ reserve ( result, end - start) ;
87
+ auto i = start;
88
+ while ( i < end) { result += ~[ v. ( i) ] ; i += 1 u; }
89
+ ret result;
90
+ }
91
+
92
+ // TODO: Remove me once we have slots.
93
+ fn slice_mut[ T ] ( & T [ mutable?] v, uint start, uint end) -> T [ mutable] {
94
+ assert ( start <= end) ;
95
+ assert ( end <= len ( v) ) ;
96
+ auto result = ~[ mutable] ;
97
+ reserve ( result, end - start) ;
98
+ auto i = start;
99
+ while ( i < end) { result += ~[ mutable v. ( i) ] ; i += 1 u; }
100
+ ret result;
101
+ }
102
+
103
+
104
+ // Mutators
105
+
106
+ // TODO
107
+
108
+
46
109
mod unsafe {
47
110
fn copy_from_buf[ T ] ( & mutable T [ ] v, * T ptr, uint count) {
48
111
ret rustrt:: ivec_copy_from_buf( v, ptr, count) ;
0 commit comments