2
2
3
3
use ptr:: addr_of;
4
4
5
- export init_op;
6
- export capacity;
7
- export build_sized, build, build_sized_opt;
8
- export map;
9
- export from_fn, from_elem;
10
- export raw;
11
- export traits;
12
-
13
5
/// Code for dealing with @-vectors. This is pretty incomplete, and
14
6
/// contains a bunch of duplication from the code for ~-vectors.
15
7
16
8
#[ abi = "cdecl" ]
17
9
extern mod rustrt {
18
- #[ legacy_exports] ;
19
- fn vec_reserve_shared_actual ( ++t : * sys:: TypeDesc ,
10
+ pub fn vec_reserve_shared_actual ( ++t : * sys:: TypeDesc ,
20
11
++v : * * vec:: raw:: VecRepr ,
21
12
++n : libc:: size_t ) ;
22
13
}
23
14
24
15
#[ abi = "rust-intrinsic" ]
25
16
extern mod rusti {
26
- #[ legacy_exports] ;
27
- fn move_val_init < T > ( & dst: T , -src : T ) ;
17
+ pub fn move_val_init < T > ( & dst: T , -src : T ) ;
28
18
}
29
19
30
20
/// Returns the number of elements the vector can hold without reallocating
31
21
#[ inline( always) ]
32
- pure fn capacity < T > ( & & v: @[ const T ] ) -> uint {
22
+ pub pure fn capacity < T > ( & & v: @[ const T ] ) -> uint {
33
23
unsafe {
34
24
let repr: * * raw :: VecRepr =
35
25
:: cast:: reinterpret_cast ( & addr_of ( v) ) ;
@@ -50,7 +40,8 @@ pure fn capacity<T>(&&v: @[const T]) -> uint {
50
40
* onto the vector being constructed.
51
41
*/
52
42
#[ inline( always) ]
53
- pure fn build_sized < A > ( size : uint , builder : fn ( push : pure fn( +A ) ) ) -> @[ A ] {
43
+ pub pure fn build_sized < A > ( size : uint ,
44
+ builder : fn ( push : pure fn( +A ) ) ) -> @[ A ] {
54
45
let mut vec = @[ ] ;
55
46
unsafe { raw:: reserve ( vec, size) ; }
56
47
builder ( |+x| unsafe { raw:: push ( vec, move x) } ) ;
@@ -68,7 +59,7 @@ pure fn build_sized<A>(size: uint, builder: fn(push: pure fn(+A))) -> @[A] {
68
59
* onto the vector being constructed.
69
60
*/
70
61
#[ inline( always) ]
71
- pure fn build < A > ( builder : fn ( push : pure fn( +A ) ) ) -> @[ A ] {
62
+ pub pure fn build < A > ( builder : fn ( push : pure fn( +A ) ) ) -> @[ A ] {
72
63
build_sized ( 4 , builder)
73
64
}
74
65
@@ -85,7 +76,7 @@ pure fn build<A>(builder: fn(push: pure fn(+A))) -> @[A] {
85
76
* onto the vector being constructed.
86
77
*/
87
78
#[ inline( always) ]
88
- pure fn build_sized_opt < A > ( size : Option < uint > ,
79
+ pub pure fn build_sized_opt < A > ( size : Option < uint > ,
89
80
builder : fn ( push : pure fn( +A ) ) ) -> @[ A ] {
90
81
build_sized ( size. get_default ( 4 ) , builder)
91
82
}
@@ -101,7 +92,7 @@ pure fn append<T: Copy>(lhs: @[T], rhs: &[const T]) -> @[T] {
101
92
102
93
103
94
/// Apply a function to each element of a vector and return the results
104
- pure fn map < T , U > ( v : & [ T ] , f : fn ( T ) -> U ) -> @[ U ] {
95
+ pub pure fn map < T , U > ( v : & [ T ] , f : fn ( T ) -> U ) -> @[ U ] {
105
96
do build_sized ( v. len ( ) ) |push| {
106
97
for vec:: each( v) |elem| {
107
98
push ( f ( * elem) ) ;
@@ -115,7 +106,7 @@ pure fn map<T, U>(v: &[T], f: fn(T) -> U) -> @[U] {
115
106
* Creates an immutable vector of size `n_elts` and initializes the elements
116
107
* to the value returned by the function `op`.
117
108
*/
118
- pure fn from_fn < T > ( n_elts : uint , op : iter:: InitOp < T > ) -> @[ T ] {
109
+ pub pure fn from_fn < T > ( n_elts : uint , op : iter:: InitOp < T > ) -> @[ T ] {
119
110
do build_sized ( n_elts) |push| {
120
111
let mut i: uint = 0 u;
121
112
while i < n_elts { push ( op ( i) ) ; i += 1 u; }
@@ -128,7 +119,7 @@ pure fn from_fn<T>(n_elts: uint, op: iter::InitOp<T>) -> @[T] {
128
119
* Creates an immutable vector of size `n_elts` and initializes the elements
129
120
* to the value `t`.
130
121
*/
131
- pure fn from_elem < T : Copy > ( n_elts : uint , t : T ) -> @[ T ] {
122
+ pub pure fn from_elem < T : Copy > ( n_elts : uint , t : T ) -> @[ T ] {
132
123
do build_sized ( n_elts) |push| {
133
124
let mut i: uint = 0 u;
134
125
while i < n_elts { push ( t) ; i += 1 u; }
@@ -137,7 +128,6 @@ pure fn from_elem<T: Copy>(n_elts: uint, t: T) -> @[T] {
137
128
138
129
#[ cfg( notest) ]
139
130
mod traits {
140
- #[ legacy_exports] ;
141
131
#[ cfg( stage0) ]
142
132
impl < T : Copy > @[ T ] : Add < & [ const T ] , @[ T ] > {
143
133
#[ inline( always) ]
@@ -159,10 +149,9 @@ mod traits {
159
149
mod traits {
160
150
#[ legacy_exports] ; }
161
151
162
- mod raw {
163
- #[ legacy_exports] ;
164
- type VecRepr = vec:: raw:: VecRepr ;
165
- type SliceRepr = vec:: raw:: SliceRepr ;
152
+ pub mod raw {
153
+ pub type VecRepr = vec:: raw:: VecRepr ;
154
+ pub type SliceRepr = vec:: raw:: SliceRepr ;
166
155
167
156
/**
168
157
* Sets the length of a vector
@@ -172,13 +161,13 @@ mod raw {
172
161
* the vector is actually the specified size.
173
162
*/
174
163
#[ inline( always) ]
175
- unsafe fn set_len < T > ( & & v: @[ const T ] , new_len : uint ) {
164
+ pub unsafe fn set_len < T > ( & & v: @[ const T ] , new_len : uint ) {
176
165
let repr: * * VecRepr = :: cast:: reinterpret_cast ( & addr_of ( v) ) ;
177
166
( * * repr) . unboxed . fill = new_len * sys:: size_of :: < T > ( ) ;
178
167
}
179
168
180
169
#[ inline( always) ]
181
- unsafe fn push < T > ( & v: @[ const T ] , +initval : T ) {
170
+ pub unsafe fn push < T > ( & v: @[ const T ] , +initval : T ) {
182
171
let repr: * * VecRepr = :: cast:: reinterpret_cast ( & addr_of ( v) ) ;
183
172
let fill = ( * * repr) . unboxed . fill ;
184
173
if ( * * repr) . unboxed . alloc > fill {
@@ -215,7 +204,7 @@ mod raw {
215
204
* * v - A vector
216
205
* * n - The number of elements to reserve space for
217
206
*/
218
- unsafe fn reserve < T > ( & v: @[ const T ] , n : uint ) {
207
+ pub unsafe fn reserve < T > ( & v: @[ const T ] , n : uint ) {
219
208
// Only make the (slow) call into the runtime if we have to
220
209
if capacity ( v) < n {
221
210
let ptr = addr_of ( v) as * * VecRepr ;
@@ -239,7 +228,7 @@ mod raw {
239
228
* * v - A vector
240
229
* * n - The number of elements to reserve space for
241
230
*/
242
- unsafe fn reserve_at_least < T > ( & v: @[ const T ] , n : uint ) {
231
+ pub unsafe fn reserve_at_least < T > ( & v: @[ const T ] , n : uint ) {
243
232
reserve ( v, uint:: next_power_of_two ( n) ) ;
244
233
}
245
234
0 commit comments