30
30
use either:: Either ;
31
31
use libc:: size_t;
32
32
33
- export Port ;
34
- export Chan ;
35
- export send;
36
- export recv;
37
- export peek;
38
- export recv_chan;
39
- export select2;
40
- export methods;
41
- export listen;
42
33
43
34
44
35
/**
@@ -48,7 +39,7 @@ export listen;
48
39
* transmitted. If a port value is copied, both copies refer to the same
49
40
* port. Ports may be associated with multiple `chan`s.
50
41
*/
51
- enum Port < T : Send > {
42
+ pub enum Port < T : Send > {
52
43
Port_ ( @PortPtr < T > )
53
44
}
54
45
@@ -64,12 +55,12 @@ enum Port<T: Send> {
64
55
* data will be silently dropped. Channels may be duplicated and
65
56
* themselves transmitted over other channels.
66
57
*/
67
- enum Chan < T : Send > {
58
+ pub enum Chan < T : Send > {
68
59
Chan_ ( port_id )
69
60
}
70
61
71
62
/// Constructs a port
72
- fn Port < T : Send > ( ) -> Port < T > {
63
+ pub fn Port < T : Send > ( ) -> Port < T > {
73
64
Port_ ( @PortPtr ( rustrt:: new_port ( sys:: size_of :: < T > ( ) as size_t ) ) )
74
65
}
75
66
@@ -92,7 +83,7 @@ impl<T: Send> Chan<T> {
92
83
}
93
84
94
85
/// Open a new receiving channel for the duration of a function
95
- fn listen < T : Send , U > ( f : fn ( Chan < T > ) -> U ) -> U {
86
+ pub fn listen < T : Send , U > ( f : fn ( Chan < T > ) -> U ) -> U {
96
87
let po = Port ( ) ;
97
88
f ( po. chan ( ) )
98
89
}
@@ -167,15 +158,15 @@ fn as_raw_port<T: Send, U>(ch: comm::Chan<T>, f: fn(*rust_port) -> U) -> U {
167
158
* Constructs a channel. The channel is bound to the port used to
168
159
* construct it.
169
160
*/
170
- fn Chan < T : Send > ( p : Port < T > ) -> Chan < T > {
161
+ pub fn Chan < T : Send > ( p : Port < T > ) -> Chan < T > {
171
162
Chan_ ( rustrt:: get_port_id ( ( * * p) . po ) )
172
163
}
173
164
174
165
/**
175
166
* Sends data over a channel. The sent data is moved into the channel,
176
167
* whereupon the caller loses access to it.
177
168
*/
178
- fn send< T : Send > ( ch : Chan < T > , +data : T ) {
169
+ pub fn send< T : Send > ( ch : Chan < T > , +data : T ) {
179
170
let Chan_ ( p) = ch;
180
171
let data_ptr = ptr:: addr_of ( data) as * ( ) ;
181
172
let res = rustrt:: rust_port_id_send ( p, data_ptr) ;
@@ -190,13 +181,13 @@ fn send<T: Send>(ch: Chan<T>, +data: T) {
190
181
* Receive from a port. If no data is available on the port then the
191
182
* task will block until data becomes available.
192
183
*/
193
- fn recv < T : Send > ( p : Port < T > ) -> T { recv_ ( ( * * p) . po ) }
184
+ pub fn recv < T : Send > ( p : Port < T > ) -> T { recv_ ( ( * * p) . po ) }
194
185
195
186
/// Returns true if there are messages available
196
- fn peek < T : Send > ( p : Port < T > ) -> bool { peek_ ( ( * * p) . po ) }
187
+ pub fn peek < T : Send > ( p : Port < T > ) -> bool { peek_ ( ( * * p) . po ) }
197
188
198
189
#[ doc( hidden) ]
199
- fn recv_chan < T : Send > ( ch : comm:: Chan < T > ) -> T {
190
+ pub fn recv_chan < T : Send > ( ch : comm:: Chan < T > ) -> T {
200
191
as_raw_port ( ch, |x|recv_ ( x) )
201
192
}
202
193
@@ -231,7 +222,7 @@ fn peek_(p: *rust_port) -> bool {
231
222
}
232
223
233
224
/// Receive on one of two ports
234
- fn select2 < A : Send , B : Send > ( p_a : Port < A > , p_b : Port < B > )
225
+ pub fn select2 < A : Send , B : Send > ( p_a : Port < A > , p_b : Port < B > )
235
226
-> Either < A , B > {
236
227
let ports = ~[ ( * * p_a) . po , ( * * p_b) . po ] ;
237
228
let yield = 0 , yieldp = ptr:: addr_of ( yield ) ;
0 commit comments