@@ -52,7 +52,7 @@ impl Default for ArrayToken {
5252}
5353
5454/// Bounded channel based on a preallocated array.
55- pub struct Channel < T > {
55+ pub ( crate ) struct Channel < T > {
5656 /// The head of the channel.
5757 ///
5858 /// 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> {
9595
9696impl < T > Channel < T > {
9797 /// Creates a bounded channel of capacity `cap`.
98- pub fn with_capacity ( cap : usize ) -> Self {
98+ pub ( crate ) fn with_capacity ( cap : usize ) -> Self {
9999 assert ! ( cap > 0 , "capacity must be positive" ) ;
100100
101101 // Compute constants `mark_bit` and `one_lap`.
@@ -138,12 +138,12 @@ impl<T> Channel<T> {
138138 }
139139
140140 /// Returns a receiver handle to the channel.
141- pub fn receiver ( & self ) -> Receiver < ' _ , T > {
141+ pub ( crate ) fn receiver ( & self ) -> Receiver < ' _ , T > {
142142 Receiver ( self )
143143 }
144144
145145 /// Returns a sender handle to the channel.
146- pub fn sender ( & self ) -> Sender < ' _ , T > {
146+ pub ( crate ) fn sender ( & self ) -> Sender < ' _ , T > {
147147 Sender ( self )
148148 }
149149
@@ -219,7 +219,7 @@ impl<T> Channel<T> {
219219 }
220220
221221 /// 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 > {
223223 // If there is no slot, the channel is disconnected.
224224 if token. array . slot . is_null ( ) {
225225 return Err ( msg) ;
@@ -309,7 +309,7 @@ impl<T> Channel<T> {
309309 }
310310
311311 /// 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 , ( ) > {
313313 if token. array . slot . is_null ( ) {
314314 // The channel is disconnected.
315315 return Err ( ( ) ) ;
@@ -327,7 +327,7 @@ impl<T> Channel<T> {
327327 }
328328
329329 /// 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 > > {
331331 let token = & mut Token :: default ( ) ;
332332 if self . start_send ( token) {
333333 unsafe { self . write ( token, msg) . map_err ( TrySendError :: Disconnected ) }
@@ -337,7 +337,11 @@ impl<T> Channel<T> {
337337 }
338338
339339 /// 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 > > {
341345 let token = & mut Token :: default ( ) ;
342346 loop {
343347 // Try sending a message several times.
@@ -386,7 +390,7 @@ impl<T> Channel<T> {
386390 }
387391
388392 /// 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 > {
390394 let token = & mut Token :: default ( ) ;
391395
392396 if self . start_recv ( token) {
@@ -397,7 +401,7 @@ impl<T> Channel<T> {
397401 }
398402
399403 /// 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 > {
401405 let token = & mut Token :: default ( ) ;
402406 loop {
403407 // Try receiving a message several times.
@@ -448,7 +452,7 @@ impl<T> Channel<T> {
448452 }
449453
450454 /// Returns the current number of messages inside the channel.
451- pub fn len ( & self ) -> usize {
455+ pub ( crate ) fn len ( & self ) -> usize {
452456 loop {
453457 // Load the tail, then load the head.
454458 let tail = self . tail . load ( Ordering :: SeqCst ) ;
@@ -473,14 +477,14 @@ impl<T> Channel<T> {
473477 }
474478
475479 /// Returns the capacity of the channel.
476- pub fn capacity ( & self ) -> Option < usize > {
480+ pub ( crate ) fn capacity ( & self ) -> Option < usize > {
477481 Some ( self . cap )
478482 }
479483
480484 /// Disconnects the channel and wakes up all blocked senders and receivers.
481485 ///
482486 /// Returns `true` if this call disconnected the channel.
483- pub fn disconnect ( & self ) -> bool {
487+ pub ( crate ) fn disconnect ( & self ) -> bool {
484488 let tail = self . tail . fetch_or ( self . mark_bit , Ordering :: SeqCst ) ;
485489
486490 if tail & self . mark_bit == 0 {
@@ -493,12 +497,12 @@ impl<T> Channel<T> {
493497 }
494498
495499 /// Returns `true` if the channel is disconnected.
496- pub fn is_disconnected ( & self ) -> bool {
500+ pub ( crate ) fn is_disconnected ( & self ) -> bool {
497501 self . tail . load ( Ordering :: SeqCst ) & self . mark_bit != 0
498502 }
499503
500504 /// Returns `true` if the channel is empty.
501- pub fn is_empty ( & self ) -> bool {
505+ pub ( crate ) fn is_empty ( & self ) -> bool {
502506 let head = self . head . load ( Ordering :: SeqCst ) ;
503507 let tail = self . tail . load ( Ordering :: SeqCst ) ;
504508
@@ -510,7 +514,7 @@ impl<T> Channel<T> {
510514 }
511515
512516 /// Returns `true` if the channel is full.
513- pub fn is_full ( & self ) -> bool {
517+ pub ( crate ) fn is_full ( & self ) -> bool {
514518 let tail = self . tail . load ( Ordering :: SeqCst ) ;
515519 let head = self . head . load ( Ordering :: SeqCst ) ;
516520
@@ -558,10 +562,10 @@ impl<T> Drop for Channel<T> {
558562}
559563
560564/// Receiver handle to a channel.
561- pub struct Receiver < ' a , T > ( & ' a Channel < T > ) ;
565+ pub ( crate ) struct Receiver < ' a , T > ( & ' a Channel < T > ) ;
562566
563567/// Sender handle to a channel.
564- pub struct Sender < ' a , T > ( & ' a Channel < T > ) ;
568+ pub ( crate ) struct Sender < ' a , T > ( & ' a Channel < T > ) ;
565569
566570impl < T > SelectHandle for Receiver < ' _ , T > {
567571 fn try_select ( & self , token : & mut Token ) -> bool {
0 commit comments