@@ -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,7 @@ 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 ( & self , msg : T , deadline : Option < Instant > ) -> Result < ( ) , SendTimeoutError < T > > {
341341 let token = & mut Token :: default ( ) ;
342342 loop {
343343 // Try sending a message several times.
@@ -386,7 +386,7 @@ impl<T> Channel<T> {
386386 }
387387
388388 /// Attempts to receive a message without blocking.
389- pub fn try_recv ( & self ) -> Result < T , TryRecvError > {
389+ pub ( crate ) fn try_recv ( & self ) -> Result < T , TryRecvError > {
390390 let token = & mut Token :: default ( ) ;
391391
392392 if self . start_recv ( token) {
@@ -397,7 +397,7 @@ impl<T> Channel<T> {
397397 }
398398
399399 /// Receives a message from the channel.
400- pub fn recv ( & self , deadline : Option < Instant > ) -> Result < T , RecvTimeoutError > {
400+ pub ( crate ) fn recv ( & self , deadline : Option < Instant > ) -> Result < T , RecvTimeoutError > {
401401 let token = & mut Token :: default ( ) ;
402402 loop {
403403 // Try receiving a message several times.
@@ -448,7 +448,7 @@ impl<T> Channel<T> {
448448 }
449449
450450 /// Returns the current number of messages inside the channel.
451- pub fn len ( & self ) -> usize {
451+ pub ( crate ) fn len ( & self ) -> usize {
452452 loop {
453453 // Load the tail, then load the head.
454454 let tail = self . tail . load ( Ordering :: SeqCst ) ;
@@ -473,14 +473,14 @@ impl<T> Channel<T> {
473473 }
474474
475475 /// Returns the capacity of the channel.
476- pub fn capacity ( & self ) -> Option < usize > {
476+ pub ( crate ) fn capacity ( & self ) -> Option < usize > {
477477 Some ( self . cap )
478478 }
479479
480480 /// Disconnects the channel and wakes up all blocked senders and receivers.
481481 ///
482482 /// Returns `true` if this call disconnected the channel.
483- pub fn disconnect ( & self ) -> bool {
483+ pub ( crate ) fn disconnect ( & self ) -> bool {
484484 let tail = self . tail . fetch_or ( self . mark_bit , Ordering :: SeqCst ) ;
485485
486486 if tail & self . mark_bit == 0 {
@@ -493,12 +493,12 @@ impl<T> Channel<T> {
493493 }
494494
495495 /// Returns `true` if the channel is disconnected.
496- pub fn is_disconnected ( & self ) -> bool {
496+ pub ( crate ) fn is_disconnected ( & self ) -> bool {
497497 self . tail . load ( Ordering :: SeqCst ) & self . mark_bit != 0
498498 }
499499
500500 /// Returns `true` if the channel is empty.
501- pub fn is_empty ( & self ) -> bool {
501+ pub ( crate ) fn is_empty ( & self ) -> bool {
502502 let head = self . head . load ( Ordering :: SeqCst ) ;
503503 let tail = self . tail . load ( Ordering :: SeqCst ) ;
504504
@@ -510,7 +510,7 @@ impl<T> Channel<T> {
510510 }
511511
512512 /// Returns `true` if the channel is full.
513- pub fn is_full ( & self ) -> bool {
513+ pub ( crate ) fn is_full ( & self ) -> bool {
514514 let tail = self . tail . load ( Ordering :: SeqCst ) ;
515515 let head = self . head . load ( Ordering :: SeqCst ) ;
516516
@@ -558,10 +558,10 @@ impl<T> Drop for Channel<T> {
558558}
559559
560560/// Receiver handle to a channel.
561- pub struct Receiver < ' a , T > ( & ' a Channel < T > ) ;
561+ pub ( crate ) struct Receiver < ' a , T > ( & ' a Channel < T > ) ;
562562
563563/// Sender handle to a channel.
564- pub struct Sender < ' a , T > ( & ' a Channel < T > ) ;
564+ pub ( crate ) struct Sender < ' a , T > ( & ' a Channel < T > ) ;
565565
566566impl < T > SelectHandle for Receiver < ' _ , T > {
567567 fn try_select ( & self , token : & mut Token ) -> bool {
0 commit comments