26
26
* still held if needed.
27
27
*/
28
28
29
- export CVec ;
30
- export CVec , c_vec_with_dtor;
31
- export get, set;
32
- export len;
33
- export ptr;
34
-
35
29
/**
36
30
* The type representing a foreign chunk of memory
37
31
*
38
32
* Wrapped in a enum for opacity; FIXME #818 when it is possible to have
39
33
* truly opaque types, this should be revisited.
40
34
*/
41
- enum CVec < T > {
35
+ pub enum CVec < T > {
42
36
CVecCtor ( { base : * mut T , len : uint , rsrc : @DtorRes } )
43
37
}
44
38
@@ -70,7 +64,7 @@ fn DtorRes(dtor: Option<fn@()>) -> DtorRes {
70
64
* * base - A foreign pointer to a buffer
71
65
* * len - The number of elements in the buffer
72
66
*/
73
- unsafe fn CVec < T > ( base : * mut T , len : uint ) -> CVec < T > {
67
+ pub unsafe fn CVec < T > ( base : * mut T , len : uint ) -> CVec < T > {
74
68
return CVecCtor ( {
75
69
base: base,
76
70
len: len,
@@ -89,7 +83,7 @@ unsafe fn CVec<T>(base: *mut T, len: uint) -> CVec<T> {
89
83
* * dtor - A function to run when the value is destructed, useful
90
84
* for freeing the buffer, etc.
91
85
*/
92
- unsafe fn c_vec_with_dtor < T > ( base : * mut T , len : uint , dtor : fn @( ) )
86
+ pub unsafe fn c_vec_with_dtor < T > ( base : * mut T , len : uint , dtor : fn @( ) )
93
87
-> CVec < T > {
94
88
return CVecCtor ( {
95
89
base: base,
@@ -107,7 +101,7 @@ unsafe fn c_vec_with_dtor<T>(base: *mut T, len: uint, dtor: fn@())
107
101
*
108
102
* Fails if `ofs` is greater or equal to the length of the vector
109
103
*/
110
- fn get < T : Copy > ( t : CVec < T > , ofs : uint ) -> T {
104
+ pub fn get < T : Copy > ( t : CVec < T > , ofs : uint ) -> T {
111
105
assert ofs < len ( t) ;
112
106
return unsafe { * ptr:: mut_offset ( ( * t) . base , ofs) } ;
113
107
}
@@ -117,7 +111,7 @@ fn get<T: Copy>(t: CVec<T>, ofs: uint) -> T {
117
111
*
118
112
* Fails if `ofs` is greater or equal to the length of the vector
119
113
*/
120
- fn set < T : Copy > ( t : CVec < T > , ofs : uint , +v : T ) {
114
+ pub fn set < T : Copy > ( t : CVec < T > , ofs : uint , +v : T ) {
121
115
assert ofs < len ( t) ;
122
116
unsafe { * ptr:: mut_offset ( ( * t) . base , ofs) = v } ;
123
117
}
@@ -127,18 +121,17 @@ fn set<T: Copy>(t: CVec<T>, ofs: uint, +v: T) {
127
121
*/
128
122
129
123
/// Returns the length of the vector
130
- fn len < T > ( t : CVec < T > ) -> uint {
124
+ pub fn len < T > ( t : CVec < T > ) -> uint {
131
125
return ( * t) . len ;
132
126
}
133
127
134
128
/// Returns a pointer to the first element of the vector
135
- unsafe fn ptr < T > ( t : CVec < T > ) -> * mut T {
129
+ pub unsafe fn ptr < T > ( t : CVec < T > ) -> * mut T {
136
130
return ( * t) . base ;
137
131
}
138
132
139
133
#[ cfg( test) ]
140
134
mod tests {
141
- #[ legacy_exports] ;
142
135
use libc:: * ;
143
136
144
137
fn malloc ( n : size_t ) -> CVec < u8 > {
0 commit comments