async_watch/
error.rs

1//! Watch error types.
2
3use std::fmt;
4
5/// Error produced when sending a value fails.
6#[derive(Debug)]
7pub struct SendError<T> {
8    pub(crate) inner: T,
9}
10
11// ===== impl SendError =====
12
13impl<T> SendError<T> {
14    /// Returns the data being sent (by [`send`](fn@crate::Sender::send))
15    /// so it can be recovered.
16    pub fn value(self) -> T {
17        self.inner
18    }
19}
20
21impl<T: fmt::Debug> fmt::Display for SendError<T> {
22    fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
23        write!(fmt, "channel closed")
24    }
25}
26
27impl<T: fmt::Debug> std::error::Error for SendError<T> {}
28
29/// Error produced when receiving a value fails.
30#[derive(Debug)]
31pub struct RecvError {}
32
33impl fmt::Display for RecvError {
34    fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
35        write!(fmt, "channel closed")
36    }
37}
38
39impl std::error::Error for RecvError {}