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 #[error("Queue is empty")]
16 QueueEmpty,
17 #[error("Channel disconnected")]
19 ChannelDisconnected,
20 #[error("Operation timed out")]
22 Timeout,
23 #[error("Operation not supported: {0}")]
25 Unsupported(String),
26 #[error("Send failed: {0}")]
28 SendFailed(String),
29 #[error("Receive failed: {0}")]
31 ReceiveFailed(String),
32}
33
34impl<T> From<crossbeam_channel::TrySendError<T>> for QueueError {
35 fn from(err: crossbeam_channel::TrySendError<T>) -> Self {
36 match err {
37 crossbeam_channel::TrySendError::Full(_) => QueueError::QueueFull,
38 crossbeam_channel::TrySendError::Disconnected(_) => QueueError::ChannelDisconnected,
39 }
40 }
41}
42
43impl From<crossbeam_channel::TryRecvError> for QueueError {
44 fn from(err: crossbeam_channel::TryRecvError) -> Self {
45 match err {
46 crossbeam_channel::TryRecvError::Empty => QueueError::QueueEmpty,
47 crossbeam_channel::TryRecvError::Disconnected => QueueError::ChannelDisconnected,
48 }
49 }
50}
51
52impl From<crossbeam_channel::RecvTimeoutError> for QueueError {
53 fn from(err: crossbeam_channel::RecvTimeoutError) -> Self {
54 match err {
55 crossbeam_channel::RecvTimeoutError::Timeout => QueueError::Timeout,
56 crossbeam_channel::RecvTimeoutError::Disconnected => QueueError::ChannelDisconnected,
57 }
58 }
59}