@@ -436,81 +436,97 @@ unsafe impl<T: Send> Send for SyncSender<T> {}
436
436
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
437
437
impl < T > !Sync for SyncSender < T > { }
438
438
439
- /// An error returned from the [`send`] function on channels.
439
+ /// An error returned from the [`Sender::send`] or [`SyncSender::send`]
440
+ /// function on **channel**s.
440
441
///
441
- /// A [` send`] operation can only fail if the receiving end of a channel is
442
+ /// A ** send** operation can only fail if the receiving end of a channel is
442
443
/// disconnected, implying that the data could never be received. The error
443
444
/// contains the data being sent as a payload so it can be recovered.
444
445
///
445
- /// [`send`]: ../../../std/sync/mpsc/struct.Sender.html#method.send
446
+ /// [`Sender::send`]: struct.Sender.html#method.send
447
+ /// [`SyncSender::send`]: struct.SyncSender.html#method.send
446
448
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
447
449
#[ derive( PartialEq , Eq , Clone , Copy ) ]
448
450
pub struct SendError < T > ( #[ stable( feature = "rust1" , since = "1.0.0" ) ] pub T ) ;
449
451
450
452
/// An error returned from the [`recv`] function on a [`Receiver`].
451
453
///
452
- /// The [`recv`] operation can only fail if the sending half of a channel is
453
- /// disconnected, implying that no further messages will ever be received.
454
+ /// The [`recv`] operation can only fail if the sending half of a
455
+ /// [`channel`] (or [`sync_channel`]) is disconnected, implying that no further
456
+ /// messages will ever be received.
454
457
///
455
- /// [`recv`]: ../../../std/sync/mpsc/struct.Receiver.html#method.recv
456
- /// [`Receiver`]: ../../../std/sync/mpsc/struct.Receiver.html
458
+ /// [`recv`]: struct.Receiver.html#method.recv
459
+ /// [`Receiver`]: struct.Receiver.html
460
+ /// [`channel`]: fn.channel.html
461
+ /// [`sync_channel`]: fn.sync_channel.html
457
462
#[ derive( PartialEq , Eq , Clone , Copy , Debug ) ]
458
463
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
459
464
pub struct RecvError ;
460
465
461
466
/// This enumeration is the list of the possible reasons that [`try_recv`] could
462
- /// not return data when called.
467
+ /// not return data when called. This can occur with both a [`channel`] and
468
+ /// a [`sync_channel`].
463
469
///
464
- /// [`try_recv`]: ../../../std/sync/mpsc/struct.Receiver.html#method.try_recv
470
+ /// [`try_recv`]: struct.Receiver.html#method.try_recv
471
+ /// [`channel`]: fn.channel.html
472
+ /// [`sync_channel`]: fn.sync_channel.html
465
473
#[ derive( PartialEq , Eq , Clone , Copy , Debug ) ]
466
474
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
467
475
pub enum TryRecvError {
468
- /// This channel is currently empty, but the sender (s) have not yet
476
+ /// This ** channel** is currently empty, but the **Sender** (s) have not yet
469
477
/// disconnected, so data may yet become available.
470
478
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
471
479
Empty ,
472
480
473
- /// This channel's sending half has become disconnected, and there will
474
- /// never be any more data received on this channel
481
+ /// The ** channel** 's sending half has become disconnected, and there will
482
+ /// never be any more data received on it.
475
483
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
476
484
Disconnected ,
477
485
}
478
486
479
- /// This enumeration is the list of possible errors that [`recv_timeout`] could
480
- /// not return data when called.
487
+ /// This enumeration is the list of possible errors that made [`recv_timeout`]
488
+ /// unable to return data when called. This can occur with both a [`channel`] and
489
+ /// a [`sync_channel`].
481
490
///
482
- /// [`recv_timeout`]: ../../../std/sync/mpsc/struct.Receiver.html#method.recv_timeout
491
+ /// [`recv_timeout`]: struct.Receiver.html#method.recv_timeout
492
+ /// [`channel`]: fn.channel.html
493
+ /// [`sync_channel`]: fn.sync_channel.html
483
494
#[ derive( PartialEq , Eq , Clone , Copy , Debug ) ]
484
495
#[ stable( feature = "mpsc_recv_timeout" , since = "1.12.0" ) ]
485
496
pub enum RecvTimeoutError {
486
- /// This channel is currently empty, but the sender (s) have not yet
497
+ /// This ** channel** is currently empty, but the **Sender** (s) have not yet
487
498
/// disconnected, so data may yet become available.
488
499
#[ stable( feature = "mpsc_recv_timeout" , since = "1.12.0" ) ]
489
500
Timeout ,
490
- /// This channel's sending half has become disconnected, and there will
491
- /// never be any more data received on this channel
501
+ /// The ** channel** 's sending half has become disconnected, and there will
502
+ /// never be any more data received on it.
492
503
#[ stable( feature = "mpsc_recv_timeout" , since = "1.12.0" ) ]
493
504
Disconnected ,
494
505
}
495
506
496
507
/// This enumeration is the list of the possible error outcomes for the
497
- /// [`SyncSender:: try_send`] method.
508
+ /// [`try_send`] method.
498
509
///
499
- /// [`SyncSender:: try_send`]: ../../../std/sync/mpsc/ struct.SyncSender.html#method.try_send
510
+ /// [`try_send`]: struct.SyncSender.html#method.try_send
500
511
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
501
512
#[ derive( PartialEq , Eq , Clone , Copy ) ]
502
513
pub enum TrySendError < T > {
503
- /// The data could not be sent on the channel because it would require that
514
+ /// The data could not be sent on the [`sync_channel`] because it would require that
504
515
/// the callee block to send the data.
505
516
///
506
517
/// If this is a buffered channel, then the buffer is full at this time. If
507
- /// this is not a buffered channel, then there is no receiver available to
518
+ /// this is not a buffered channel, then there is no [`Receiver`] available to
508
519
/// acquire the data.
520
+ ///
521
+ /// [`sync_channel`]: fn.sync_channel.html
522
+ /// [`Receiver`]: struct.Receiver.html
509
523
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
510
524
Full ( #[ stable( feature = "rust1" , since = "1.0.0" ) ] T ) ,
511
525
512
- /// This channel 's receiving half has disconnected, so the data could not be
526
+ /// This [`sync_channel`] 's receiving half has disconnected, so the data could not be
513
527
/// sent. The data is returned back to the callee in this case.
528
+ ///
529
+ /// [`sync_channel`]: fn.sync_channel.html
514
530
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
515
531
Disconnected ( #[ stable( feature = "rust1" , since = "1.0.0" ) ] T ) ,
516
532
}
@@ -544,36 +560,46 @@ impl<T> UnsafeFlavor<T> for Receiver<T> {
544
560
}
545
561
546
562
/// Creates a new asynchronous channel, returning the sender/receiver halves.
547
- /// All data sent on the sender will become available on the receiver, and no
548
- /// send will block the calling thread (this channel has an "infinite buffer").
563
+ /// All data sent on the [`Sender`] will become available on the [`Receiver`] in
564
+ /// the same order as it was sent, and no [`send`] will block the calling thread
565
+ /// (this channel has an "infinite buffer", unlike [`sync_channel`], which will
566
+ /// block after its buffer limit is reached). [`recv`] will block until a message
567
+ /// is available.
568
+ ///
569
+ /// The [`Sender`] can be cloned to [`send`] to the same channel multiple times, but
570
+ /// only one [`Receiver`] is supported.
549
571
///
550
572
/// If the [`Receiver`] is disconnected while trying to [`send`] with the
551
- /// [`Sender`], the [`send`] method will return an error.
573
+ /// [`Sender`], the [`send`] method will return a [`SendError`]. Similarly, If the
574
+ /// [`Sender`] is disconnected while trying to [`recv`], the [`recv`] method will
575
+ /// return a [`RecvError`].
552
576
///
553
- /// [`send`]: ../../../std/sync/mpsc/struct.Sender.html#method.send
554
- /// [`Sender`]: ../../../std/sync/mpsc/struct.Sender.html
555
- /// [`Receiver`]: ../../../std/sync/mpsc/struct.Receiver.html
577
+ /// [`send`]: struct.Sender.html#method.send
578
+ /// [`recv`]: struct.Receiver.html#method.recv
579
+ /// [`Sender`]: struct.Sender.html
580
+ /// [`Receiver`]: struct.Receiver.html
581
+ /// [`sync_channel`]: fn.sync_channel.html
582
+ /// [`SendError`]: struct.SendError.html
583
+ /// [`RecvError`]: struct.RecvError.html
556
584
///
557
585
/// # Examples
558
586
///
559
587
/// ```
560
588
/// use std::sync::mpsc::channel;
561
589
/// use std::thread;
562
590
///
563
- /// // tx is the sending half (tx for transmission), and rx is the receiving
564
- /// // half (rx for receiving).
565
- /// let (tx, rx) = channel();
591
+ /// let (sender, receiver) = channel();
566
592
///
567
593
/// // Spawn off an expensive computation
568
594
/// thread::spawn(move|| {
569
595
/// # fn expensive_computation() {}
570
- /// tx .send(expensive_computation()).unwrap();
596
+ /// sender .send(expensive_computation()).unwrap();
571
597
/// });
572
598
///
573
599
/// // Do some useful work for awhile
574
600
///
575
601
/// // Let's see what that answer was
576
- /// println!("{:?}", rx .recv().unwrap());
602
+ /// println!("{:?}", receiver .recv().unwrap());
577
603
/// ```
578
604
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
579
605
pub fn channel < T > ( ) -> ( Sender < T > , Receiver < T > ) {
@@ -582,43 +608,51 @@ pub fn channel<T>() -> (Sender<T>, Receiver<T>) {
582
608
}
583
609
584
610
/// Creates a new synchronous, bounded channel.
585
- ///
586
- /// Like asynchronous channels, the [`Receiver`] will block until a message
587
- /// becomes available. These channels differ greatly in the semantics of the
588
- /// sender from asynchronous channels , however.
611
+ /// All data sent on the [`SyncSender`] will become available on the [`Receiver`]
612
+ /// in the same order as it was sent. Like asynchronous [`channel`]s, the
613
+ /// [`Receiver`] will block until a message becomes available. `sync_channel`
614
+ /// differs greatly in the semantics of the sender , however.
589
615
///
590
616
/// This channel has an internal buffer on which messages will be queued.
591
617
/// `bound` specifies the buffer size. When the internal buffer becomes full,
592
618
/// future sends will *block* waiting for the buffer to open up. Note that a
593
619
/// buffer size of 0 is valid, in which case this becomes "rendezvous channel"
594
- /// where each [`send`] will not return until a recv is paired with it.
620
+ /// where each [`send`] will not return until a [`recv`] is paired with it.
621
+ ///
622
+ /// The [`SyncSender`] can be cloned to [`send`] to the same channel multiple
623
+ /// times, but only one [`Receiver`] is supported.
595
624
///
596
- /// Like asynchronous channels, if the [`Receiver`] is disconnected while
597
- /// trying to [`send`] with the [`SyncSender`], the [`send`] method will
598
- /// return an error.
625
+ /// Like asynchronous channels, if the [`Receiver`] is disconnected while trying
626
+ /// to [`send`] with the [`SyncSender`], the [`send`] method will return a
627
+ /// [`SendError`]. Similarly, If the [`SyncSender`] is disconnected while trying
628
+ /// to [`recv`], the [`recv`] method will return a [`RecvError`].
599
629
///
600
- /// [`send`]: ../../../std/sync/mpsc/struct.SyncSender.html#method.send
601
- /// [`SyncSender`]: ../../../std/sync/mpsc/struct.SyncSender.html
602
- /// [`Receiver`]: ../../../std/sync/mpsc/struct.Receiver.html
630
+ /// [`channel`]: fn.channel.html
631
+ /// [`send`]: struct.SyncSender.html#method.send
632
+ /// [`recv`]: struct.Receiver.html#method.recv
633
+ /// [`SyncSender`]: struct.SyncSender.html
634
+ /// [`Receiver`]: struct.Receiver.html
635
+ /// [`SendError`]: struct.SendError.html
636
+ /// [`RecvError`]: struct.RecvError.html
603
637
///
604
638
/// # Examples
605
639
///
606
640
/// ```
607
641
/// use std::sync::mpsc::sync_channel;
608
642
/// use std::thread;
609
643
///
610
- /// let (tx, rx ) = sync_channel(1);
644
+ /// let (sender, receiver ) = sync_channel(1);
611
645
///
612
646
/// // this returns immediately
613
- /// tx .send(1).unwrap();
647
+ /// sender .send(1).unwrap();
614
648
///
615
649
/// thread::spawn(move|| {
616
650
/// // this will block until the previous message has been received
617
- /// tx .send(2).unwrap();
651
+ /// sender .send(2).unwrap();
618
652
/// });
619
653
///
620
- /// assert_eq!(rx .recv().unwrap(), 1);
621
- /// assert_eq!(rx .recv().unwrap(), 2);
654
+ /// assert_eq!(receiver .recv().unwrap(), 1);
655
+ /// assert_eq!(receiver .recv().unwrap(), 2);
622
656
/// ```
623
657
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
624
658
pub fn sync_channel < T > ( bound : usize ) -> ( SyncSender < T > , Receiver < T > ) {
0 commit comments