]>
git.proxmox.com Git - rustc.git/blob - vendor/crossbeam-channel/src/err.rs
4 /// An error returned from the [`send`] method.
6 /// The message could not be sent because the channel is disconnected.
8 /// The error contains the message so it can be recovered.
10 /// [`send`]: super::Sender::send
11 #[derive(PartialEq, Eq, Clone, Copy)]
12 pub struct SendError
<T
>(pub T
);
14 /// An error returned from the [`try_send`] method.
16 /// The error contains the message being sent so it can be recovered.
18 /// [`try_send`]: super::Sender::try_send
19 #[derive(PartialEq, Eq, Clone, Copy)]
20 pub enum TrySendError
<T
> {
21 /// The message could not be sent because the channel is full.
23 /// If this is a zero-capacity channel, then the error indicates that there was no receiver
24 /// available to receive the message at the time.
27 /// The message could not be sent because the channel is disconnected.
31 /// An error returned from the [`send_timeout`] method.
33 /// The error contains the message being sent so it can be recovered.
35 /// [`send_timeout`]: super::Sender::send_timeout
36 #[derive(PartialEq, Eq, Clone, Copy)]
37 pub enum SendTimeoutError
<T
> {
38 /// The message could not be sent because the channel is full and the operation timed out.
40 /// If this is a zero-capacity channel, then the error indicates that there was no receiver
41 /// available to receive the message and the operation timed out.
44 /// The message could not be sent because the channel is disconnected.
48 /// An error returned from the [`recv`] method.
50 /// A message could not be received because the channel is empty and disconnected.
52 /// [`recv`]: super::Receiver::recv
53 #[derive(PartialEq, Eq, Clone, Copy, Debug)]
56 /// An error returned from the [`try_recv`] method.
58 /// [`try_recv`]: super::Receiver::try_recv
59 #[derive(PartialEq, Eq, Clone, Copy, Debug)]
60 pub enum TryRecvError
{
61 /// A message could not be received because the channel is empty.
63 /// If this is a zero-capacity channel, then the error indicates that there was no sender
64 /// available to send a message at the time.
67 /// The message could not be received because the channel is empty and disconnected.
71 /// An error returned from the [`recv_timeout`] method.
73 /// [`recv_timeout`]: super::Receiver::recv_timeout
74 #[derive(PartialEq, Eq, Clone, Copy, Debug)]
75 pub enum RecvTimeoutError
{
76 /// A message could not be received because the channel is empty and the operation timed out.
78 /// If this is a zero-capacity channel, then the error indicates that there was no sender
79 /// available to send a message and the operation timed out.
82 /// The message could not be received because the channel is empty and disconnected.
86 /// An error returned from the [`try_select`] method.
88 /// Failed because none of the channel operations were ready.
90 /// [`try_select`]: super::Select::try_select
91 #[derive(PartialEq, Eq, Clone, Copy, Debug)]
92 pub struct TrySelectError
;
94 /// An error returned from the [`select_timeout`] method.
96 /// Failed because none of the channel operations became ready before the timeout.
98 /// [`select_timeout`]: super::Select::select_timeout
99 #[derive(PartialEq, Eq, Clone, Copy, Debug)]
100 pub struct SelectTimeoutError
;
102 /// An error returned from the [`try_ready`] method.
104 /// Failed because none of the channel operations were ready.
106 /// [`try_ready`]: super::Select::try_ready
107 #[derive(PartialEq, Eq, Clone, Copy, Debug)]
108 pub struct TryReadyError
;
110 /// An error returned from the [`ready_timeout`] method.
112 /// Failed because none of the channel operations became ready before the timeout.
114 /// [`ready_timeout`]: super::Select::ready_timeout
115 #[derive(PartialEq, Eq, Clone, Copy, Debug)]
116 pub struct ReadyTimeoutError
;
118 impl<T
> fmt
::Debug
for SendError
<T
> {
119 fn fmt(&self, f
: &mut fmt
::Formatter
<'_
>) -> fmt
::Result
{
120 "SendError(..)".fmt(f
)
124 impl<T
> fmt
::Display
for SendError
<T
> {
125 fn fmt(&self, f
: &mut fmt
::Formatter
<'_
>) -> fmt
::Result
{
126 "sending on a disconnected channel".fmt(f
)
130 impl<T
: Send
> error
::Error
for SendError
<T
> {}
132 impl<T
> SendError
<T
> {
133 /// Unwraps the message.
138 /// use crossbeam_channel::unbounded;
140 /// let (s, r) = unbounded();
143 /// if let Err(err) = s.send("foo") {
144 /// assert_eq!(err.into_inner(), "foo");
147 pub fn into_inner(self) -> T
{
152 impl<T
> fmt
::Debug
for TrySendError
<T
> {
153 fn fmt(&self, f
: &mut fmt
::Formatter
<'_
>) -> fmt
::Result
{
155 TrySendError
::Full(..) => "Full(..)".fmt(f
),
156 TrySendError
::Disconnected(..) => "Disconnected(..)".fmt(f
),
161 impl<T
> fmt
::Display
for TrySendError
<T
> {
162 fn fmt(&self, f
: &mut fmt
::Formatter
<'_
>) -> fmt
::Result
{
164 TrySendError
::Full(..) => "sending on a full channel".fmt(f
),
165 TrySendError
::Disconnected(..) => "sending on a disconnected channel".fmt(f
),
170 impl<T
: Send
> error
::Error
for TrySendError
<T
> {}
172 impl<T
> From
<SendError
<T
>> for TrySendError
<T
> {
173 fn from(err
: SendError
<T
>) -> TrySendError
<T
> {
175 SendError(t
) => TrySendError
::Disconnected(t
),
180 impl<T
> TrySendError
<T
> {
181 /// Unwraps the message.
186 /// use crossbeam_channel::bounded;
188 /// let (s, r) = bounded(0);
190 /// if let Err(err) = s.try_send("foo") {
191 /// assert_eq!(err.into_inner(), "foo");
194 pub fn into_inner(self) -> T
{
196 TrySendError
::Full(v
) => v
,
197 TrySendError
::Disconnected(v
) => v
,
201 /// Returns `true` if the send operation failed because the channel is full.
202 pub fn is_full(&self) -> bool
{
204 TrySendError
::Full(_
) => true,
209 /// Returns `true` if the send operation failed because the channel is disconnected.
210 pub fn is_disconnected(&self) -> bool
{
212 TrySendError
::Disconnected(_
) => true,
218 impl<T
> fmt
::Debug
for SendTimeoutError
<T
> {
219 fn fmt(&self, f
: &mut fmt
::Formatter
<'_
>) -> fmt
::Result
{
220 "SendTimeoutError(..)".fmt(f
)
224 impl<T
> fmt
::Display
for SendTimeoutError
<T
> {
225 fn fmt(&self, f
: &mut fmt
::Formatter
<'_
>) -> fmt
::Result
{
227 SendTimeoutError
::Timeout(..) => "timed out waiting on send operation".fmt(f
),
228 SendTimeoutError
::Disconnected(..) => "sending on a disconnected channel".fmt(f
),
233 impl<T
: Send
> error
::Error
for SendTimeoutError
<T
> {}
235 impl<T
> From
<SendError
<T
>> for SendTimeoutError
<T
> {
236 fn from(err
: SendError
<T
>) -> SendTimeoutError
<T
> {
238 SendError(e
) => SendTimeoutError
::Disconnected(e
),
243 impl<T
> SendTimeoutError
<T
> {
244 /// Unwraps the message.
249 /// use std::time::Duration;
250 /// use crossbeam_channel::unbounded;
252 /// let (s, r) = unbounded();
254 /// if let Err(err) = s.send_timeout("foo", Duration::from_secs(1)) {
255 /// assert_eq!(err.into_inner(), "foo");
258 pub fn into_inner(self) -> T
{
260 SendTimeoutError
::Timeout(v
) => v
,
261 SendTimeoutError
::Disconnected(v
) => v
,
265 /// Returns `true` if the send operation timed out.
266 pub fn is_timeout(&self) -> bool
{
268 SendTimeoutError
::Timeout(_
) => true,
273 /// Returns `true` if the send operation failed because the channel is disconnected.
274 pub fn is_disconnected(&self) -> bool
{
276 SendTimeoutError
::Disconnected(_
) => true,
282 impl fmt
::Display
for RecvError
{
283 fn fmt(&self, f
: &mut fmt
::Formatter
<'_
>) -> fmt
::Result
{
284 "receiving on an empty and disconnected channel".fmt(f
)
288 impl error
::Error
for RecvError {}
290 impl fmt
::Display
for TryRecvError
{
291 fn fmt(&self, f
: &mut fmt
::Formatter
<'_
>) -> fmt
::Result
{
293 TryRecvError
::Empty
=> "receiving on an empty channel".fmt(f
),
294 TryRecvError
::Disconnected
=> "receiving on an empty and disconnected channel".fmt(f
),
299 impl error
::Error
for TryRecvError {}
301 impl From
<RecvError
> for TryRecvError
{
302 fn from(err
: RecvError
) -> TryRecvError
{
304 RecvError
=> TryRecvError
::Disconnected
,
310 /// Returns `true` if the receive operation failed because the channel is empty.
311 pub fn is_empty(&self) -> bool
{
313 TryRecvError
::Empty
=> true,
318 /// Returns `true` if the receive operation failed because the channel is disconnected.
319 pub fn is_disconnected(&self) -> bool
{
321 TryRecvError
::Disconnected
=> true,
327 impl fmt
::Display
for RecvTimeoutError
{
328 fn fmt(&self, f
: &mut fmt
::Formatter
<'_
>) -> fmt
::Result
{
330 RecvTimeoutError
::Timeout
=> "timed out waiting on receive operation".fmt(f
),
331 RecvTimeoutError
::Disconnected
=> "channel is empty and disconnected".fmt(f
),
336 impl error
::Error
for RecvTimeoutError {}
338 impl From
<RecvError
> for RecvTimeoutError
{
339 fn from(err
: RecvError
) -> RecvTimeoutError
{
341 RecvError
=> RecvTimeoutError
::Disconnected
,
346 impl RecvTimeoutError
{
347 /// Returns `true` if the receive operation timed out.
348 pub fn is_timeout(&self) -> bool
{
350 RecvTimeoutError
::Timeout
=> true,
355 /// Returns `true` if the receive operation failed because the channel is disconnected.
356 pub fn is_disconnected(&self) -> bool
{
358 RecvTimeoutError
::Disconnected
=> true,
364 impl fmt
::Display
for TrySelectError
{
365 fn fmt(&self, f
: &mut fmt
::Formatter
<'_
>) -> fmt
::Result
{
366 "all operations in select would block".fmt(f
)
370 impl error
::Error
for TrySelectError {}
372 impl fmt
::Display
for SelectTimeoutError
{
373 fn fmt(&self, f
: &mut fmt
::Formatter
<'_
>) -> fmt
::Result
{
374 "timed out waiting on select".fmt(f
)
378 impl error
::Error
for SelectTimeoutError {}