]>
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`]: struct.Sender.html#method.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`]: struct.Sender.html#method.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`]: struct.Sender.html#method.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`]: struct.Receiver.html#method.recv
53 #[derive(PartialEq, Eq, Clone, Copy, Debug)]
56 /// An error returned from the [`try_recv`] method.
58 /// [`try_recv`]: struct.Receiver.html#method.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`]: struct.Receiver.html#method.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`]: struct.Select.html#method.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`]: struct.Select.html#method.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`]: struct.Select.html#method.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`]: struct.Select.html#method.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
> {
131 fn description(&self) -> &str {
132 "sending on a disconnected channel"
135 fn cause(&self) -> Option
<&error
::Error
> {
140 impl<T
> SendError
<T
> {
141 /// Unwraps the message.
146 /// use crossbeam_channel::unbounded;
148 /// let (s, r) = unbounded();
151 /// if let Err(err) = s.send("foo") {
152 /// assert_eq!(err.into_inner(), "foo");
155 pub fn into_inner(self) -> T
{
160 impl<T
> fmt
::Debug
for TrySendError
<T
> {
161 fn fmt(&self, f
: &mut fmt
::Formatter
) -> fmt
::Result
{
163 TrySendError
::Full(..) => "Full(..)".fmt(f
),
164 TrySendError
::Disconnected(..) => "Disconnected(..)".fmt(f
),
169 impl<T
> fmt
::Display
for TrySendError
<T
> {
170 fn fmt(&self, f
: &mut fmt
::Formatter
) -> fmt
::Result
{
172 TrySendError
::Full(..) => "sending on a full channel".fmt(f
),
173 TrySendError
::Disconnected(..) => "sending on a disconnected channel".fmt(f
),
178 impl<T
: Send
> error
::Error
for TrySendError
<T
> {
179 fn description(&self) -> &str {
181 TrySendError
::Full(..) => "sending on a full channel",
182 TrySendError
::Disconnected(..) => "sending on a disconnected channel",
186 fn cause(&self) -> Option
<&error
::Error
> {
191 impl<T
> From
<SendError
<T
>> for TrySendError
<T
> {
192 fn from(err
: SendError
<T
>) -> TrySendError
<T
> {
194 SendError(t
) => TrySendError
::Disconnected(t
),
199 impl<T
> TrySendError
<T
> {
200 /// Unwraps the message.
205 /// use crossbeam_channel::bounded;
207 /// let (s, r) = bounded(0);
209 /// if let Err(err) = s.try_send("foo") {
210 /// assert_eq!(err.into_inner(), "foo");
213 pub fn into_inner(self) -> T
{
215 TrySendError
::Full(v
) => v
,
216 TrySendError
::Disconnected(v
) => v
,
220 /// Returns `true` if the send operation failed because the channel is full.
221 pub fn is_full(&self) -> bool
{
223 TrySendError
::Full(_
) => true,
228 /// Returns `true` if the send operation failed because the channel is disconnected.
229 pub fn is_disconnected(&self) -> bool
{
231 TrySendError
::Disconnected(_
) => true,
237 impl<T
> fmt
::Debug
for SendTimeoutError
<T
> {
238 fn fmt(&self, f
: &mut fmt
::Formatter
) -> fmt
::Result
{
239 "SendTimeoutError(..)".fmt(f
)
243 impl<T
> fmt
::Display
for SendTimeoutError
<T
> {
244 fn fmt(&self, f
: &mut fmt
::Formatter
) -> fmt
::Result
{
246 SendTimeoutError
::Timeout(..) => "timed out waiting on send operation".fmt(f
),
247 SendTimeoutError
::Disconnected(..) => "sending on a disconnected channel".fmt(f
),
252 impl<T
: Send
> error
::Error
for SendTimeoutError
<T
> {
253 fn description(&self) -> &str {
254 "sending on an empty and disconnected channel"
257 fn cause(&self) -> Option
<&error
::Error
> {
262 impl<T
> From
<SendError
<T
>> for SendTimeoutError
<T
> {
263 fn from(err
: SendError
<T
>) -> SendTimeoutError
<T
> {
265 SendError(e
) => SendTimeoutError
::Disconnected(e
),
270 impl<T
> SendTimeoutError
<T
> {
271 /// Unwraps the message.
276 /// use std::time::Duration;
277 /// use crossbeam_channel::unbounded;
279 /// let (s, r) = unbounded();
281 /// if let Err(err) = s.send_timeout("foo", Duration::from_secs(1)) {
282 /// assert_eq!(err.into_inner(), "foo");
285 pub fn into_inner(self) -> T
{
287 SendTimeoutError
::Timeout(v
) => v
,
288 SendTimeoutError
::Disconnected(v
) => v
,
292 /// Returns `true` if the send operation timed out.
293 pub fn is_timeout(&self) -> bool
{
295 SendTimeoutError
::Timeout(_
) => true,
300 /// Returns `true` if the send operation failed because the channel is disconnected.
301 pub fn is_disconnected(&self) -> bool
{
303 SendTimeoutError
::Disconnected(_
) => true,
309 impl fmt
::Display
for RecvError
{
310 fn fmt(&self, f
: &mut fmt
::Formatter
) -> fmt
::Result
{
311 "receiving on an empty and disconnected channel".fmt(f
)
315 impl error
::Error
for RecvError
{
316 fn description(&self) -> &str {
317 "receiving on an empty and disconnected channel"
320 fn cause(&self) -> Option
<&error
::Error
> {
325 impl fmt
::Display
for TryRecvError
{
326 fn fmt(&self, f
: &mut fmt
::Formatter
) -> fmt
::Result
{
328 TryRecvError
::Empty
=> "receiving on an empty channel".fmt(f
),
329 TryRecvError
::Disconnected
=> "receiving on an empty and disconnected channel".fmt(f
),
334 impl error
::Error
for TryRecvError
{
335 fn description(&self) -> &str {
337 TryRecvError
::Empty
=> "receiving on an empty channel",
338 TryRecvError
::Disconnected
=> "receiving on an empty and disconnected channel",
342 fn cause(&self) -> Option
<&error
::Error
> {
347 impl From
<RecvError
> for TryRecvError
{
348 fn from(err
: RecvError
) -> TryRecvError
{
350 RecvError
=> TryRecvError
::Disconnected
,
356 /// Returns `true` if the receive operation failed because the channel is empty.
357 pub fn is_empty(&self) -> bool
{
359 TryRecvError
::Empty
=> true,
364 /// Returns `true` if the receive operation failed because the channel is disconnected.
365 pub fn is_disconnected(&self) -> bool
{
367 TryRecvError
::Disconnected
=> true,
373 impl fmt
::Display
for RecvTimeoutError
{
374 fn fmt(&self, f
: &mut fmt
::Formatter
) -> fmt
::Result
{
376 RecvTimeoutError
::Timeout
=> "timed out waiting on receive operation".fmt(f
),
377 RecvTimeoutError
::Disconnected
=> "channel is empty and disconnected".fmt(f
),
382 impl error
::Error
for RecvTimeoutError
{
383 fn description(&self) -> &str {
385 RecvTimeoutError
::Timeout
=> "timed out waiting on receive operation",
386 RecvTimeoutError
::Disconnected
=> "channel is empty and disconnected",
390 fn cause(&self) -> Option
<&error
::Error
> {
395 impl From
<RecvError
> for RecvTimeoutError
{
396 fn from(err
: RecvError
) -> RecvTimeoutError
{
398 RecvError
=> RecvTimeoutError
::Disconnected
,
403 impl RecvTimeoutError
{
404 /// Returns `true` if the receive operation timed out.
405 pub fn is_timeout(&self) -> bool
{
407 RecvTimeoutError
::Timeout
=> true,
412 /// Returns `true` if the receive operation failed because the channel is disconnected.
413 pub fn is_disconnected(&self) -> bool
{
415 RecvTimeoutError
::Disconnected
=> true,
421 impl fmt
::Display
for TrySelectError
{
422 fn fmt(&self, f
: &mut fmt
::Formatter
) -> fmt
::Result
{
423 "all operations in select would block".fmt(f
)
427 impl error
::Error
for TrySelectError
{
428 fn description(&self) -> &str {
429 "all operations in select would block"
432 fn cause(&self) -> Option
<&error
::Error
> {
437 impl fmt
::Display
for SelectTimeoutError
{
438 fn fmt(&self, f
: &mut fmt
::Formatter
) -> fmt
::Result
{
439 "timed out waiting on select".fmt(f
)
443 impl error
::Error
for SelectTimeoutError
{
444 fn description(&self) -> &str {
445 "timed out waiting on select"
448 fn cause(&self) -> Option
<&error
::Error
> {