@@ -52,7 +52,7 @@ impl Default for ArrayToken {
52
52
}
53
53
54
54
/// Bounded channel based on a preallocated array.
55
- pub struct Channel < T > {
55
+ pub ( crate ) struct Channel < T > {
56
56
/// The head of the channel.
57
57
///
58
58
/// This value is a "stamp" consisting of an index into the buffer, a mark bit, and a lap, but
@@ -95,7 +95,7 @@ pub struct Channel<T> {
95
95
96
96
impl < T > Channel < T > {
97
97
/// Creates a bounded channel of capacity `cap`.
98
- pub fn with_capacity ( cap : usize ) -> Self {
98
+ pub ( crate ) fn with_capacity ( cap : usize ) -> Self {
99
99
assert ! ( cap > 0 , "capacity must be positive" ) ;
100
100
101
101
// Compute constants `mark_bit` and `one_lap`.
@@ -138,12 +138,12 @@ impl<T> Channel<T> {
138
138
}
139
139
140
140
/// Returns a receiver handle to the channel.
141
- pub fn receiver ( & self ) -> Receiver < ' _ , T > {
141
+ pub ( crate ) fn receiver ( & self ) -> Receiver < ' _ , T > {
142
142
Receiver ( self )
143
143
}
144
144
145
145
/// Returns a sender handle to the channel.
146
- pub fn sender ( & self ) -> Sender < ' _ , T > {
146
+ pub ( crate ) fn sender ( & self ) -> Sender < ' _ , T > {
147
147
Sender ( self )
148
148
}
149
149
@@ -219,7 +219,7 @@ impl<T> Channel<T> {
219
219
}
220
220
221
221
/// Writes a message into the channel.
222
- pub unsafe fn write ( & self , token : & mut Token , msg : T ) -> Result < ( ) , T > {
222
+ pub ( crate ) unsafe fn write ( & self , token : & mut Token , msg : T ) -> Result < ( ) , T > {
223
223
// If there is no slot, the channel is disconnected.
224
224
if token. array . slot . is_null ( ) {
225
225
return Err ( msg) ;
@@ -309,7 +309,7 @@ impl<T> Channel<T> {
309
309
}
310
310
311
311
/// Reads a message from the channel.
312
- pub unsafe fn read ( & self , token : & mut Token ) -> Result < T , ( ) > {
312
+ pub ( crate ) unsafe fn read ( & self , token : & mut Token ) -> Result < T , ( ) > {
313
313
if token. array . slot . is_null ( ) {
314
314
// The channel is disconnected.
315
315
return Err ( ( ) ) ;
@@ -327,7 +327,7 @@ impl<T> Channel<T> {
327
327
}
328
328
329
329
/// Attempts to send a message into the channel.
330
- pub fn try_send ( & self , msg : T ) -> Result < ( ) , TrySendError < T > > {
330
+ pub ( crate ) fn try_send ( & self , msg : T ) -> Result < ( ) , TrySendError < T > > {
331
331
let token = & mut Token :: default ( ) ;
332
332
if self . start_send ( token) {
333
333
unsafe { self . write ( token, msg) . map_err ( TrySendError :: Disconnected ) }
@@ -337,7 +337,11 @@ impl<T> Channel<T> {
337
337
}
338
338
339
339
/// Sends a message into the channel.
340
- pub fn send ( & self , msg : T , deadline : Option < Instant > ) -> Result < ( ) , SendTimeoutError < T > > {
340
+ pub ( crate ) fn send (
341
+ & self ,
342
+ msg : T ,
343
+ deadline : Option < Instant > ,
344
+ ) -> Result < ( ) , SendTimeoutError < T > > {
341
345
let token = & mut Token :: default ( ) ;
342
346
loop {
343
347
// Try sending a message several times.
@@ -386,7 +390,7 @@ impl<T> Channel<T> {
386
390
}
387
391
388
392
/// Attempts to receive a message without blocking.
389
- pub fn try_recv ( & self ) -> Result < T , TryRecvError > {
393
+ pub ( crate ) fn try_recv ( & self ) -> Result < T , TryRecvError > {
390
394
let token = & mut Token :: default ( ) ;
391
395
392
396
if self . start_recv ( token) {
@@ -397,7 +401,7 @@ impl<T> Channel<T> {
397
401
}
398
402
399
403
/// Receives a message from the channel.
400
- pub fn recv ( & self , deadline : Option < Instant > ) -> Result < T , RecvTimeoutError > {
404
+ pub ( crate ) fn recv ( & self , deadline : Option < Instant > ) -> Result < T , RecvTimeoutError > {
401
405
let token = & mut Token :: default ( ) ;
402
406
loop {
403
407
// Try receiving a message several times.
@@ -448,7 +452,7 @@ impl<T> Channel<T> {
448
452
}
449
453
450
454
/// Returns the current number of messages inside the channel.
451
- pub fn len ( & self ) -> usize {
455
+ pub ( crate ) fn len ( & self ) -> usize {
452
456
loop {
453
457
// Load the tail, then load the head.
454
458
let tail = self . tail . load ( Ordering :: SeqCst ) ;
@@ -473,14 +477,14 @@ impl<T> Channel<T> {
473
477
}
474
478
475
479
/// Returns the capacity of the channel.
476
- pub fn capacity ( & self ) -> Option < usize > {
480
+ pub ( crate ) fn capacity ( & self ) -> Option < usize > {
477
481
Some ( self . cap )
478
482
}
479
483
480
484
/// Disconnects the channel and wakes up all blocked senders and receivers.
481
485
///
482
486
/// Returns `true` if this call disconnected the channel.
483
- pub fn disconnect ( & self ) -> bool {
487
+ pub ( crate ) fn disconnect ( & self ) -> bool {
484
488
let tail = self . tail . fetch_or ( self . mark_bit , Ordering :: SeqCst ) ;
485
489
486
490
if tail & self . mark_bit == 0 {
@@ -493,12 +497,12 @@ impl<T> Channel<T> {
493
497
}
494
498
495
499
/// Returns `true` if the channel is disconnected.
496
- pub fn is_disconnected ( & self ) -> bool {
500
+ pub ( crate ) fn is_disconnected ( & self ) -> bool {
497
501
self . tail . load ( Ordering :: SeqCst ) & self . mark_bit != 0
498
502
}
499
503
500
504
/// Returns `true` if the channel is empty.
501
- pub fn is_empty ( & self ) -> bool {
505
+ pub ( crate ) fn is_empty ( & self ) -> bool {
502
506
let head = self . head . load ( Ordering :: SeqCst ) ;
503
507
let tail = self . tail . load ( Ordering :: SeqCst ) ;
504
508
@@ -510,7 +514,7 @@ impl<T> Channel<T> {
510
514
}
511
515
512
516
/// Returns `true` if the channel is full.
513
- pub fn is_full ( & self ) -> bool {
517
+ pub ( crate ) fn is_full ( & self ) -> bool {
514
518
let tail = self . tail . load ( Ordering :: SeqCst ) ;
515
519
let head = self . head . load ( Ordering :: SeqCst ) ;
516
520
@@ -558,10 +562,10 @@ impl<T> Drop for Channel<T> {
558
562
}
559
563
560
564
/// Receiver handle to a channel.
561
- pub struct Receiver < ' a , T > ( & ' a Channel < T > ) ;
565
+ pub ( crate ) struct Receiver < ' a , T > ( & ' a Channel < T > ) ;
562
566
563
567
/// Sender handle to a channel.
564
- pub struct Sender < ' a , T > ( & ' a Channel < T > ) ;
568
+ pub ( crate ) struct Sender < ' a , T > ( & ' a Channel < T > ) ;
565
569
566
570
impl < T > SelectHandle for Receiver < ' _ , T > {
567
571
fn try_select ( & self , token : & mut Token ) -> bool {
0 commit comments