/// An error returned from the [`send`] method. /// /// The message could not be sent because the channel is disconnected. /// /// The error contains the message so it can be recovered. /// /// [`send`]: super::Sender::send #[derive(PartialEq, Eq, Clone, Copy)] pubstruct SendError<T>(pub T);
/// An error returned from the [`try_send`] method. /// /// The error contains the message being sent so it can be recovered. /// /// [`try_send`]: super::Sender::try_send #[derive(PartialEq, Eq, Clone, Copy)] pubenum TrySendError<T> { /// The message could not be sent because the channel is full. /// /// If this is a zero-capacity channel, then the error indicates that there was no receiver /// available to receive the message at the time.
Full(T),
/// The message could not be sent because the channel is disconnected.
Disconnected(T),
}
/// An error returned from the [`send_timeout`] method. /// /// The error contains the message being sent so it can be recovered. /// /// [`send_timeout`]: super::Sender::send_timeout #[derive(PartialEq, Eq, Clone, Copy)] pubenum SendTimeoutError<T> { /// The message could not be sent because the channel is full and the operation timed out. /// /// If this is a zero-capacity channel, then the error indicates that there was no receiver /// available to receive the message and the operation timed out.
Timeout(T),
/// The message could not be sent because the channel is disconnected.
Disconnected(T),
}
/// An error returned from the [`recv`] method. /// /// A message could not be received because the channel is empty and disconnected. /// /// [`recv`]: super::Receiver::recv #[derive(PartialEq, Eq, Clone, Copy, Debug)] pubstruct RecvError;
/// An error returned from the [`try_recv`] method. /// /// [`try_recv`]: super::Receiver::try_recv #[derive(PartialEq, Eq, Clone, Copy, Debug)] pubenum TryRecvError { /// A message could not be received because the channel is empty. /// /// If this is a zero-capacity channel, then the error indicates that there was no sender /// available to send a message at the time.
Empty,
/// The message could not be received because the channel is empty and disconnected.
Disconnected,
}
/// An error returned from the [`recv_timeout`] method. /// /// [`recv_timeout`]: super::Receiver::recv_timeout #[derive(PartialEq, Eq, Clone, Copy, Debug)] pubenum RecvTimeoutError { /// A message could not be received because the channel is empty and the operation timed out. /// /// If this is a zero-capacity channel, then the error indicates that there was no sender /// available to send a message and the operation timed out.
Timeout,
/// The message could not be received because the channel is empty and disconnected.
Disconnected,
}
/// An error returned from the [`try_select`] method. /// /// Failed because none of the channel operations were ready. /// /// [`try_select`]: super::Select::try_select #[derive(PartialEq, Eq, Clone, Copy, Debug)] pubstruct TrySelectError;
/// An error returned from the [`select_timeout`] method. /// /// Failed because none of the channel operations became ready before the timeout. /// /// [`select_timeout`]: super::Select::select_timeout #[derive(PartialEq, Eq, Clone, Copy, Debug)] pubstruct SelectTimeoutError;
/// An error returned from the [`try_ready`] method. /// /// Failed because none of the channel operations were ready. /// /// [`try_ready`]: super::Select::try_ready #[derive(PartialEq, Eq, Clone, Copy, Debug)] pubstruct TryReadyError;
/// An error returned from the [`ready_timeout`] method. /// /// Failed because none of the channel operations became ready before the timeout. /// /// [`ready_timeout`]: super::Select::ready_timeout #[derive(PartialEq, Eq, Clone, Copy, Debug)] pubstruct ReadyTimeoutError;
impl<T> fmt::Display for TrySendError<T> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self {
TrySendError::Full(..) => "sending on a full channel".fmt(f),
TrySendError::Disconnected(..) => "sending on a disconnected channel".fmt(f),
}
}
}
impl<T: Send> error::Error for TrySendError<T> {}
impl<T> From<SendError<T>> for TrySendError<T> { fn from(err: SendError<T>) -> TrySendError<T> { match err {
SendError(t) => TrySendError::Disconnected(t),
}
}
}
impl<T> TrySendError<T> { /// Unwraps the message. /// /// # Examples /// /// ``` /// use crossbeam_channel::bounded; /// /// let (s, r) = bounded(0); /// /// if let Err(err) = s.try_send("foo") { /// assert_eq!(err.into_inner(), "foo"); /// } /// ``` pubfn into_inner(self) -> T { matchself {
TrySendError::Full(v) => v,
TrySendError::Disconnected(v) => v,
}
}
/// Returns `true` if the send operation failed because the channel is full. pubfn is_full(&self) -> bool { matchself {
TrySendError::Full(_) => true,
_ => false,
}
}
/// Returns `true` if the send operation failed because the channel is disconnected. pubfn is_disconnected(&self) -> bool { matchself {
TrySendError::Disconnected(_) => true,
_ => false,
}
}
}
/// Returns `true` if the send operation failed because the channel is disconnected. pubfn is_disconnected(&self) -> bool { matchself {
SendTimeoutError::Disconnected(_) => true,
_ => false,
}
}
}
impl fmt::Display for RecvError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { "receiving on an empty and disconnected channel".fmt(f)
}
}
impl error::Error for RecvError {}
impl fmt::Display for TryRecvError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self {
TryRecvError::Empty => "receiving on an empty channel".fmt(f),
TryRecvError::Disconnected => "receiving on an empty and disconnected channel".fmt(f),
}
}
}
impl error::Error for TryRecvError {}
impl From<RecvError> for TryRecvError { fn from(err: RecvError) -> TryRecvError { match err {
RecvError => TryRecvError::Disconnected,
}
}
}
impl TryRecvError { /// Returns `true` if the receive operation failed because the channel is empty. pubfn is_empty(&self) -> bool { matchself {
TryRecvError::Empty => true,
_ => false,
}
}
/// Returns `true` if the receive operation failed because the channel is disconnected. pubfn is_disconnected(&self) -> bool { matchself {
TryRecvError::Disconnected => true,
_ => false,
}
}
}
impl fmt::Display for RecvTimeoutError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self {
RecvTimeoutError::Timeout => "timed out waiting on receive operation".fmt(f),
RecvTimeoutError::Disconnected => "channel is empty and disconnected".fmt(f),
}
}
}
impl error::Error for RecvTimeoutError {}
impl From<RecvError> for RecvTimeoutError { fn from(err: RecvError) -> RecvTimeoutError { match err {
RecvError => RecvTimeoutError::Disconnected,
}
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.