Skip to main content

rxing/
exceptions.rs

1#[cfg(feature = "serde")]
2use serde::{Deserialize, Serialize};
3use thiserror::Error;
4
5#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6#[derive(Error, Debug, PartialEq, Eq, Clone)]
7pub enum Exceptions {
8    #[error("IllegalArgumentException{}", if .0.is_empty() { String::new() } else { format!(" - {}", .0) })]
9    IllegalArgumentException(String),
10    #[error("UnsupportedOperationException{}", if .0.is_empty() { String::new()  } else { format!(" - {}", .0) })]
11    UnsupportedOperationException(String),
12    #[error("IllegalStateException{}", if .0.is_empty() { String::new()  } else { format!(" - {}", .0) })]
13    IllegalStateException(String),
14    #[error("ArithmeticException{}", if .0.is_empty() { String::new()  } else { format!(" - {}", .0) })]
15    ArithmeticException(String),
16    #[error("NotFoundException{}", if .0.is_empty() { String::new()  } else { format!(" - {}", .0) })]
17    NotFoundException(String),
18    #[error("FormatException{}", if .0.is_empty() { String::new()  } else { format!(" - {}", .0) })]
19    FormatException(String),
20    #[error("ChecksumException{}", if .0.is_empty() { String::new()  } else { format!(" - {}", .0) })]
21    ChecksumException(String),
22    #[error("ReaderException{}", if .0.is_empty() { String::new()  } else { format!(" - {}", .0) })]
23    ReaderException(String),
24    #[error("WriterException{}", if .0.is_empty() { String::new()  } else { format!(" - {}", .0) })]
25    WriterException(String),
26    #[error("ReedSolomonException{}", if .0.is_empty() { String::new()  } else { format!(" - {}", .0) })]
27    ReedSolomonException(String),
28    #[error("IndexOutOfBoundsException{}", if .0.is_empty() { String::new()  } else { format!(" - {}", .0) })]
29    IndexOutOfBoundsException(String),
30    #[error("RuntimeException{}", if .0.is_empty() { String::new()  } else { format!(" - {}", .0) })]
31    RuntimeException(String),
32    #[error("ParseException{}", if .0.is_empty() { String::new()  } else { format!(" - {}", .0) })]
33    ParseException(String),
34    #[error("ReaderDecodeException")]
35    ReaderDecodeException(),
36}
37
38impl Exceptions {
39    pub const ILLEGAL_ARGUMENT: Self = Self::IllegalArgumentException(String::new());
40    pub fn illegal_argument_with<I: Into<String>>(x: I) -> Self {
41        Self::IllegalArgumentException(x.into())
42    }
43
44    pub const UNSUPPORTED_OPERATION: Self = Self::UnsupportedOperationException(String::new());
45    pub fn unsupported_operation_with<I: Into<String>>(x: I) -> Self {
46        Self::UnsupportedOperationException(x.into())
47    }
48
49    pub const ILLEGAL_STATE: Self = Self::IllegalStateException(String::new());
50    pub fn illegal_state_with<I: Into<String>>(x: I) -> Self {
51        Self::IllegalStateException(x.into())
52    }
53
54    pub const ARITHMETIC: Self = Self::ArithmeticException(String::new());
55    pub fn arithmetic_with<I: Into<String>>(x: I) -> Self {
56        Self::ArithmeticException(x.into())
57    }
58
59    pub const NOT_FOUND: Self = Self::NotFoundException(String::new());
60    pub fn not_found_with<I: Into<String>>(x: I) -> Self {
61        Self::NotFoundException(x.into())
62    }
63
64    pub const FORMAT: Self = Self::FormatException(String::new());
65    pub fn format_with<I: Into<String>>(x: I) -> Self {
66        Self::FormatException(x.into())
67    }
68
69    pub const CHECKSUM: Self = Self::ChecksumException(String::new());
70    pub fn checksum_with<I: Into<String>>(x: I) -> Self {
71        Self::ChecksumException(x.into())
72    }
73
74    pub const READER: Self = Self::ReaderException(String::new());
75    pub fn reader_with<I: Into<String>>(x: I) -> Self {
76        Self::ReaderException(x.into())
77    }
78
79    pub const WRITER: Self = Self::WriterException(String::new());
80    pub fn writer_with<I: Into<String>>(x: I) -> Self {
81        Self::WriterException(x.into())
82    }
83
84    pub const REED_SOLOMON: Self = Self::ReedSolomonException(String::new());
85    pub fn reed_solomon_with<I: Into<String>>(x: I) -> Self {
86        Self::ReedSolomonException(x.into())
87    }
88
89    pub const INDEX_OUT_OF_BOUNDS: Self = Self::IndexOutOfBoundsException(String::new());
90    pub fn index_out_of_bounds_with<I: Into<String>>(x: I) -> Self {
91        Self::IndexOutOfBoundsException(x.into())
92    }
93
94    pub const RUNTIME: Self = Self::RuntimeException(String::new());
95    pub fn runtime_with<I: Into<String>>(x: I) -> Self {
96        Self::RuntimeException(x.into())
97    }
98
99    pub const PARSE: Self = Self::ParseException(String::new());
100    pub fn parse_with<I: Into<String>>(x: I) -> Self {
101        Self::ParseException(x.into())
102    }
103}