bitmac/
error.rs

1use std::ops::Range;
2
3#[derive(Debug, thiserror::Error)]
4#[error("index '{actual_idx}' out of bounds {bounds:?}")]
5pub struct OutOfBoundsError {
6    actual_idx: usize,
7    bounds: Range<usize>,
8}
9
10impl OutOfBoundsError {
11    pub(crate) fn new(actual_idx: usize, bounds: Range<usize>) -> Self {
12        Self { actual_idx, bounds }
13    }
14}
15
16#[derive(Debug, thiserror::Error)]
17#[error("container size is small: {details}")]
18pub struct SmallContainerSizeError {
19    details: String,
20}
21
22impl SmallContainerSizeError {
23    /// Creates new error with details.
24    pub(crate) fn new<C>(details: C) -> Self
25    where
26        C: Into<String>,
27    {
28        Self {
29            details: details.into(),
30        }
31    }
32}
33
34#[derive(Debug, thiserror::Error)]
35#[error("the size of the bitmap cannot be increased: {details}")]
36pub struct ResizeError {
37    details: String,
38}
39
40impl ResizeError {
41    /// Creates new error with details.
42    pub fn new<C>(details: C) -> Self
43    where
44        C: Into<String>,
45    {
46        Self {
47            details: details.into(),
48        }
49    }
50}
51
52#[derive(Debug, thiserror::Error)]
53#[error("creation of a container with the specified number of slots failed: {details}")]
54pub struct WithSlotsError {
55    details: String,
56}
57
58impl WithSlotsError {
59    /// Creates new error with details.
60    pub fn new<C>(details: C) -> Self
61    where
62        C: Into<String>,
63    {
64        Self {
65            details: details.into(),
66        }
67    }
68}
69
70#[derive(Debug, thiserror::Error)]
71pub enum IntersectionError {
72    #[error(transparent)]
73    SmallContainerSizeError(#[from] SmallContainerSizeError),
74    #[error(transparent)]
75    WithSlotsError(#[from] WithSlotsError),
76}
77
78#[derive(Debug, thiserror::Error)]
79pub enum UnionError {
80    #[error(transparent)]
81    SmallContainerSizeError(#[from] SmallContainerSizeError),
82    #[error(transparent)]
83    WithSlotsError(#[from] WithSlotsError),
84}