Skip to main content

rill_core/queues/
error.rs

1//! Queue operation error types.
2
3use thiserror::Error;
4
5/// Result type alias for queue operations.
6pub type QueueResult<T> = Result<T, QueueError>;
7
8/// Errors that can occur during queue operations.
9#[derive(Error, Debug, PartialEq)]
10pub enum QueueError {
11    /// The queue is full and cannot accept more elements.
12    #[error("Queue is full")]
13    QueueFull,
14    /// The queue is empty and has no elements to pop.
15    #[error("Queue is empty")]
16    QueueEmpty,
17    /// The channel has been disconnected (all senders/receivers dropped).
18    #[error("Channel disconnected")]
19    ChannelDisconnected,
20    /// A queue operation timed out.
21    #[error("Operation timed out")]
22    Timeout,
23    /// The requested operation is not supported by this queue type.
24    #[error("Operation not supported: {0}")]
25    Unsupported(String),
26    /// Failed to send data through the queue.
27    #[error("Send failed: {0}")]
28    SendFailed(String),
29    /// Failed to receive data from the queue.
30    #[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}