Adding links around Sender/SyncSender/Receiver errors; Adding more documentation to channel() and sync_channel(); adding more links #29377
This commit is contained in:
parent
a61011761d
commit
28a232a59a
2 changed files with 87 additions and 51 deletions
|
@ -436,81 +436,97 @@ unsafe impl<T: Send> Send for SyncSender<T> {}
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl<T> !Sync for SyncSender<T> {}
|
impl<T> !Sync for SyncSender<T> {}
|
||||||
|
|
||||||
/// An error returned from the [`send`] function on channels.
|
/// An error returned from the [`Sender::send`] or [`SyncSender::send`]
|
||||||
|
/// function on **channel**s.
|
||||||
///
|
///
|
||||||
/// A [`send`] operation can only fail if the receiving end of a channel is
|
/// A **send** operation can only fail if the receiving end of a channel is
|
||||||
/// disconnected, implying that the data could never be received. The error
|
/// disconnected, implying that the data could never be received. The error
|
||||||
/// contains the data being sent as a payload so it can be recovered.
|
/// contains the data being sent as a payload so it can be recovered.
|
||||||
///
|
///
|
||||||
/// [`send`]: ../../../std/sync/mpsc/struct.Sender.html#method.send
|
/// [`Sender::send`]: struct.Sender.html#method.send
|
||||||
|
/// [`SyncSender::send`]: struct.SyncSender.html#method.send
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[derive(PartialEq, Eq, Clone, Copy)]
|
#[derive(PartialEq, Eq, Clone, Copy)]
|
||||||
pub struct SendError<T>(#[stable(feature = "rust1", since = "1.0.0")] pub T);
|
pub struct SendError<T>(#[stable(feature = "rust1", since = "1.0.0")] pub T);
|
||||||
|
|
||||||
/// An error returned from the [`recv`] function on a [`Receiver`].
|
/// An error returned from the [`recv`] function on a [`Receiver`].
|
||||||
///
|
///
|
||||||
/// The [`recv`] operation can only fail if the sending half of a channel is
|
/// The [`recv`] operation can only fail if the sending half of a
|
||||||
/// disconnected, implying that no further messages will ever be received.
|
/// [`channel`] (or [`sync_channel`]) is disconnected, implying that no further
|
||||||
|
/// messages will ever be received.
|
||||||
///
|
///
|
||||||
/// [`recv`]: ../../../std/sync/mpsc/struct.Receiver.html#method.recv
|
/// [`recv`]: struct.Receiver.html#method.recv
|
||||||
/// [`Receiver`]: ../../../std/sync/mpsc/struct.Receiver.html
|
/// [`Receiver`]: struct.Receiver.html
|
||||||
|
/// [`channel`]: fn.channel.html
|
||||||
|
/// [`sync_channel`]: fn.sync_channel.html
|
||||||
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
|
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub struct RecvError;
|
pub struct RecvError;
|
||||||
|
|
||||||
/// This enumeration is the list of the possible reasons that [`try_recv`] could
|
/// This enumeration is the list of the possible reasons that [`try_recv`] could
|
||||||
/// not return data when called.
|
/// not return data when called. This can occur with both a [`channel`] and
|
||||||
|
/// a [`sync_channel`].
|
||||||
///
|
///
|
||||||
/// [`try_recv`]: ../../../std/sync/mpsc/struct.Receiver.html#method.try_recv
|
/// [`try_recv`]: struct.Receiver.html#method.try_recv
|
||||||
|
/// [`channel`]: fn.channel.html
|
||||||
|
/// [`sync_channel`]: fn.sync_channel.html
|
||||||
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
|
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub enum TryRecvError {
|
pub enum TryRecvError {
|
||||||
/// This channel is currently empty, but the sender(s) have not yet
|
/// This **channel** is currently empty, but the **Sender**(s) have not yet
|
||||||
/// disconnected, so data may yet become available.
|
/// disconnected, so data may yet become available.
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
Empty,
|
Empty,
|
||||||
|
|
||||||
/// This channel's sending half has become disconnected, and there will
|
/// The **channel**'s sending half has become disconnected, and there will
|
||||||
/// never be any more data received on this channel
|
/// never be any more data received on it.
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
Disconnected,
|
Disconnected,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This enumeration is the list of possible errors that [`recv_timeout`] could
|
/// This enumeration is the list of possible errors that made [`recv_timeout`]
|
||||||
/// not return data when called.
|
/// unable to return data when called. This can occur with both a [`channel`] and
|
||||||
|
/// a [`sync_channel`].
|
||||||
///
|
///
|
||||||
/// [`recv_timeout`]: ../../../std/sync/mpsc/struct.Receiver.html#method.recv_timeout
|
/// [`recv_timeout`]: struct.Receiver.html#method.recv_timeout
|
||||||
|
/// [`channel`]: fn.channel.html
|
||||||
|
/// [`sync_channel`]: fn.sync_channel.html
|
||||||
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
|
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
|
||||||
#[stable(feature = "mpsc_recv_timeout", since = "1.12.0")]
|
#[stable(feature = "mpsc_recv_timeout", since = "1.12.0")]
|
||||||
pub enum RecvTimeoutError {
|
pub enum RecvTimeoutError {
|
||||||
/// This channel is currently empty, but the sender(s) have not yet
|
/// This **channel** is currently empty, but the **Sender**(s) have not yet
|
||||||
/// disconnected, so data may yet become available.
|
/// disconnected, so data may yet become available.
|
||||||
#[stable(feature = "mpsc_recv_timeout", since = "1.12.0")]
|
#[stable(feature = "mpsc_recv_timeout", since = "1.12.0")]
|
||||||
Timeout,
|
Timeout,
|
||||||
/// This channel's sending half has become disconnected, and there will
|
/// The **channel**'s sending half has become disconnected, and there will
|
||||||
/// never be any more data received on this channel
|
/// never be any more data received on it.
|
||||||
#[stable(feature = "mpsc_recv_timeout", since = "1.12.0")]
|
#[stable(feature = "mpsc_recv_timeout", since = "1.12.0")]
|
||||||
Disconnected,
|
Disconnected,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This enumeration is the list of the possible error outcomes for the
|
/// This enumeration is the list of the possible error outcomes for the
|
||||||
/// [`SyncSender::try_send`] method.
|
/// [`try_send`] method.
|
||||||
///
|
///
|
||||||
/// [`SyncSender::try_send`]: ../../../std/sync/mpsc/struct.SyncSender.html#method.try_send
|
/// [`try_send`]: struct.SyncSender.html#method.try_send
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[derive(PartialEq, Eq, Clone, Copy)]
|
#[derive(PartialEq, Eq, Clone, Copy)]
|
||||||
pub enum TrySendError<T> {
|
pub enum TrySendError<T> {
|
||||||
/// The data could not be sent on the channel because it would require that
|
/// The data could not be sent on the [`sync_channel`] because it would require that
|
||||||
/// the callee block to send the data.
|
/// the callee block to send the data.
|
||||||
///
|
///
|
||||||
/// If this is a buffered channel, then the buffer is full at this time. If
|
/// If this is a buffered channel, then the buffer is full at this time. If
|
||||||
/// this is not a buffered channel, then there is no receiver available to
|
/// this is not a buffered channel, then there is no [`Receiver`] available to
|
||||||
/// acquire the data.
|
/// acquire the data.
|
||||||
|
///
|
||||||
|
/// [`sync_channel`]: fn.sync_channel.html
|
||||||
|
/// [`Receiver`]: struct.Receiver.html
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
Full(#[stable(feature = "rust1", since = "1.0.0")] T),
|
Full(#[stable(feature = "rust1", since = "1.0.0")] T),
|
||||||
|
|
||||||
/// This channel's receiving half has disconnected, so the data could not be
|
/// This [`sync_channel`]'s receiving half has disconnected, so the data could not be
|
||||||
/// sent. The data is returned back to the callee in this case.
|
/// sent. The data is returned back to the callee in this case.
|
||||||
|
///
|
||||||
|
/// [`sync_channel`]: fn.sync_channel.html
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
Disconnected(#[stable(feature = "rust1", since = "1.0.0")] T),
|
Disconnected(#[stable(feature = "rust1", since = "1.0.0")] T),
|
||||||
}
|
}
|
||||||
|
@ -544,15 +560,27 @@ impl<T> UnsafeFlavor<T> for Receiver<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new asynchronous channel, returning the sender/receiver halves.
|
/// Creates a new asynchronous channel, returning the sender/receiver halves.
|
||||||
/// All data sent on the sender will become available on the receiver, and no
|
/// All data sent on the [`Sender`] will become available on the [`Receiver`] in
|
||||||
/// send will block the calling thread (this channel has an "infinite buffer").
|
/// the same order as it was sent, and no [`send`] will block the calling thread
|
||||||
|
/// (this channel has an "infinite buffer", unlike [`sync_channel`], which will
|
||||||
|
/// block after its buffer limit is reached). [`recv`] will block until a message
|
||||||
|
/// is available.
|
||||||
|
///
|
||||||
|
/// The [`Sender`] can be cloned to [`send`] to the same channel multiple times, but
|
||||||
|
/// only one [`Receiver`] is supported.
|
||||||
///
|
///
|
||||||
/// If the [`Receiver`] is disconnected while trying to [`send`] with the
|
/// If the [`Receiver`] is disconnected while trying to [`send`] with the
|
||||||
/// [`Sender`], the [`send`] method will return an error.
|
/// [`Sender`], the [`send`] method will return a [`SendError`]. Similarly, If the
|
||||||
|
/// [`Sender`] is disconnected while trying to [`recv`], the [`recv`] method will
|
||||||
|
/// return a [`RecvError`].
|
||||||
///
|
///
|
||||||
/// [`send`]: ../../../std/sync/mpsc/struct.Sender.html#method.send
|
/// [`send`]: struct.Sender.html#method.send
|
||||||
/// [`Sender`]: ../../../std/sync/mpsc/struct.Sender.html
|
/// [`recv`]: struct.Receiver.html#method.recv
|
||||||
/// [`Receiver`]: ../../../std/sync/mpsc/struct.Receiver.html
|
/// [`Sender`]: struct.Sender.html
|
||||||
|
/// [`Receiver`]: struct.Receiver.html
|
||||||
|
/// [`sync_channel`]: fn.sync_channel.html
|
||||||
|
/// [`SendError`]: struct.SendError.html
|
||||||
|
/// [`RecvError`]: struct.RecvError.html
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
|
@ -560,20 +588,18 @@ impl<T> UnsafeFlavor<T> for Receiver<T> {
|
||||||
/// use std::sync::mpsc::channel;
|
/// use std::sync::mpsc::channel;
|
||||||
/// use std::thread;
|
/// use std::thread;
|
||||||
///
|
///
|
||||||
/// // tx is the sending half (tx for transmission), and rx is the receiving
|
/// let (sender, receiver) = channel();
|
||||||
/// // half (rx for receiving).
|
|
||||||
/// let (tx, rx) = channel();
|
|
||||||
///
|
///
|
||||||
/// // Spawn off an expensive computation
|
/// // Spawn off an expensive computation
|
||||||
/// thread::spawn(move|| {
|
/// thread::spawn(move|| {
|
||||||
/// # fn expensive_computation() {}
|
/// # fn expensive_computation() {}
|
||||||
/// tx.send(expensive_computation()).unwrap();
|
/// sender.send(expensive_computation()).unwrap();
|
||||||
/// });
|
/// });
|
||||||
///
|
///
|
||||||
/// // Do some useful work for awhile
|
/// // Do some useful work for awhile
|
||||||
///
|
///
|
||||||
/// // Let's see what that answer was
|
/// // Let's see what that answer was
|
||||||
/// println!("{:?}", rx.recv().unwrap());
|
/// println!("{:?}", receiver.recv().unwrap());
|
||||||
/// ```
|
/// ```
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub fn channel<T>() -> (Sender<T>, Receiver<T>) {
|
pub fn channel<T>() -> (Sender<T>, Receiver<T>) {
|
||||||
|
@ -582,24 +608,32 @@ pub fn channel<T>() -> (Sender<T>, Receiver<T>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new synchronous, bounded channel.
|
/// Creates a new synchronous, bounded channel.
|
||||||
///
|
/// All data sent on the [`SyncSender`] will become available on the [`Receiver`]
|
||||||
/// Like asynchronous channels, the [`Receiver`] will block until a message
|
/// in the same order as it was sent. Like asynchronous [`channel`]s, the
|
||||||
/// becomes available. These channels differ greatly in the semantics of the
|
/// [`Receiver`] will block until a message becomes available. `sync_channel`
|
||||||
/// sender from asynchronous channels, however.
|
/// differs greatly in the semantics of the sender, however.
|
||||||
///
|
///
|
||||||
/// This channel has an internal buffer on which messages will be queued.
|
/// This channel has an internal buffer on which messages will be queued.
|
||||||
/// `bound` specifies the buffer size. When the internal buffer becomes full,
|
/// `bound` specifies the buffer size. When the internal buffer becomes full,
|
||||||
/// future sends will *block* waiting for the buffer to open up. Note that a
|
/// future sends will *block* waiting for the buffer to open up. Note that a
|
||||||
/// buffer size of 0 is valid, in which case this becomes "rendezvous channel"
|
/// buffer size of 0 is valid, in which case this becomes "rendezvous channel"
|
||||||
/// where each [`send`] will not return until a recv is paired with it.
|
/// where each [`send`] will not return until a [`recv`] is paired with it.
|
||||||
///
|
///
|
||||||
/// Like asynchronous channels, if the [`Receiver`] is disconnected while
|
/// The [`SyncSender`] can be cloned to [`send`] to the same channel multiple
|
||||||
/// trying to [`send`] with the [`SyncSender`], the [`send`] method will
|
/// times, but only one [`Receiver`] is supported.
|
||||||
/// return an error.
|
|
||||||
///
|
///
|
||||||
/// [`send`]: ../../../std/sync/mpsc/struct.SyncSender.html#method.send
|
/// Like asynchronous channels, if the [`Receiver`] is disconnected while trying
|
||||||
/// [`SyncSender`]: ../../../std/sync/mpsc/struct.SyncSender.html
|
/// to [`send`] with the [`SyncSender`], the [`send`] method will return a
|
||||||
/// [`Receiver`]: ../../../std/sync/mpsc/struct.Receiver.html
|
/// [`SendError`]. Similarly, If the [`SyncSender`] is disconnected while trying
|
||||||
|
/// to [`recv`], the [`recv`] method will return a [`RecvError`].
|
||||||
|
///
|
||||||
|
/// [`channel`]: fn.channel.html
|
||||||
|
/// [`send`]: struct.SyncSender.html#method.send
|
||||||
|
/// [`recv`]: struct.Receiver.html#method.recv
|
||||||
|
/// [`SyncSender`]: struct.SyncSender.html
|
||||||
|
/// [`Receiver`]: struct.Receiver.html
|
||||||
|
/// [`SendError`]: struct.SendError.html
|
||||||
|
/// [`RecvError`]: struct.RecvError.html
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
|
@ -607,18 +641,18 @@ pub fn channel<T>() -> (Sender<T>, Receiver<T>) {
|
||||||
/// use std::sync::mpsc::sync_channel;
|
/// use std::sync::mpsc::sync_channel;
|
||||||
/// use std::thread;
|
/// use std::thread;
|
||||||
///
|
///
|
||||||
/// let (tx, rx) = sync_channel(1);
|
/// let (sender, receiver) = sync_channel(1);
|
||||||
///
|
///
|
||||||
/// // this returns immediately
|
/// // this returns immediately
|
||||||
/// tx.send(1).unwrap();
|
/// sender.send(1).unwrap();
|
||||||
///
|
///
|
||||||
/// thread::spawn(move|| {
|
/// thread::spawn(move|| {
|
||||||
/// // this will block until the previous message has been received
|
/// // this will block until the previous message has been received
|
||||||
/// tx.send(2).unwrap();
|
/// sender.send(2).unwrap();
|
||||||
/// });
|
/// });
|
||||||
///
|
///
|
||||||
/// assert_eq!(rx.recv().unwrap(), 1);
|
/// assert_eq!(receiver.recv().unwrap(), 1);
|
||||||
/// assert_eq!(rx.recv().unwrap(), 2);
|
/// assert_eq!(receiver.recv().unwrap(), 2);
|
||||||
/// ```
|
/// ```
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub fn sync_channel<T>(bound: usize) -> (SyncSender<T>, Receiver<T>) {
|
pub fn sync_channel<T>(bound: usize) -> (SyncSender<T>, Receiver<T>) {
|
||||||
|
|
|
@ -73,7 +73,9 @@ pub struct PoisonError<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An enumeration of possible errors which can occur while calling the
|
/// An enumeration of possible errors which can occur while calling the
|
||||||
/// `try_lock` method.
|
/// [`try_lock`] method.
|
||||||
|
///
|
||||||
|
/// [`try_lock`]: struct.Mutex.html#method.try_lock
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub enum TryLockError<T> {
|
pub enum TryLockError<T> {
|
||||||
/// The lock could not be acquired because another thread failed while holding
|
/// The lock could not be acquired because another thread failed while holding
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue