rill_core/queues/
error.rs1use thiserror::Error;
4
5pub type QueueResult<T> = Result<T, QueueError>;
7
8#[derive(Error, Debug, PartialEq)]
10pub enum QueueError {
11 #[error("Queue is full")]
13 QueueFull,
14
15 #[error("Queue is empty")]
17 QueueEmpty,
18
19 #[error("Channel disconnected")]
21 ChannelDisconnected,
22
23 #[error("Operation timed out")]
25 Timeout,
26
27 #[error("Operation not supported: {0}")]
29 Unsupported(String),
30
31 #[error("Send failed: {0}")]
33 SendFailed(String),
34
35 #[error("Receive failed: {0}")]
37 ReceiveFailed(String),
38}
39
40impl<T> From<crossbeam_channel::TrySendError<T>> for QueueError {
41 fn from(err: crossbeam_channel::TrySendError<T>) -> Self {
42 match err {
43 crossbeam_channel::TrySendError::Full(_) => QueueError::QueueFull,
44 crossbeam_channel::TrySendError::Disconnected(_) => QueueError::ChannelDisconnected,
45 }
46 }
47}
48
49impl From<crossbeam_channel::TryRecvError> for QueueError {
50 fn from(err: crossbeam_channel::TryRecvError) -> Self {
51 match err {
52 crossbeam_channel::TryRecvError::Empty => QueueError::QueueEmpty,
53 crossbeam_channel::TryRecvError::Disconnected => QueueError::ChannelDisconnected,
54 }
55 }
56}
57
58impl From<crossbeam_channel::RecvTimeoutError> for QueueError {
59 fn from(err: crossbeam_channel::RecvTimeoutError) -> Self {
60 match err {
61 crossbeam_channel::RecvTimeoutError::Timeout => QueueError::Timeout,
62 crossbeam_channel::RecvTimeoutError::Disconnected => QueueError::ChannelDisconnected,
63 }
64 }
65}