Skip to main content

rstl_queue/
error.rs

1use core::fmt;
2
3#[derive(Debug, Clone, PartialEq, Eq)]
4pub enum QueueError {
5    InvalidCapacity {
6        capacity: usize,
7    },
8    InsufficientCapacity {
9        current_size: usize,
10        requested_capacity: usize,
11    },
12}
13
14impl fmt::Display for QueueError {
15    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
16        match self {
17            Self::InvalidCapacity { capacity } => {
18                write!(
19                    f,
20                    "[CircularQueue] capacity is expected to be a positive integer, but got ({capacity})."
21                )
22            }
23            Self::InsufficientCapacity {
24                current_size,
25                requested_capacity,
26            } => {
27                write!(
28                    f,
29                    "[CircularQueue] failed to resize, the new queue space is insufficient. current size ({current_size}), requested capacity ({requested_capacity})."
30                )
31            }
32        }
33    }
34}
35
36impl std::error::Error for QueueError {}