Skip to main content

tightbeam/standards/
error.rs

1#[cfg(not(feature = "std"))]
2extern crate alloc;
3#[cfg(not(feature = "std"))]
4use alloc::string::String;
5
6#[cfg(feature = "derive")]
7use crate::Errorizable;
8
9#[cfg(feature = "standards-rfc")]
10#[cfg_attr(feature = "derive", derive(Errorizable))]
11#[derive(Debug, Clone, PartialEq, Eq)]
12pub enum RFCError {
13	#[cfg(feature = "standards-rfc")]
14	#[cfg_attr(feature = "derive", error("{0}"))]
15	#[cfg_attr(feature = "derive", from)]
16	RFC5424Error(crate::standards::rfc::rfc5424::RFC5424Error),
17}
18
19#[cfg(feature = "standards-iso")]
20#[cfg_attr(feature = "derive", derive(Errorizable))]
21#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
22pub enum ISOError {
23	#[cfg_attr(feature = "derive", error("ISO error: {0}"))]
24	Message(String),
25}
26
27#[cfg_attr(feature = "derive", derive(Errorizable))]
28#[derive(Debug, Clone, PartialEq, Eq)]
29pub enum StandardError {
30	#[cfg_attr(feature = "derive", error("{0}"))]
31	#[cfg_attr(feature = "derive", from)]
32	RFC(RFCError),
33	#[cfg_attr(feature = "derive", error("{0}"))]
34	#[cfg_attr(feature = "derive", from)]
35	ISO(ISOError),
36}
37
38#[cfg(not(feature = "derive"))]
39impl From<RFCError> for StandardError {
40	fn from(e: RFCError) -> Self {
41		StandardError::RFC(e)
42	}
43}
44
45#[cfg(not(feature = "derive"))]
46impl From<ISOError> for StandardError {
47	fn from(e: ISOError) -> Self {
48		StandardError::ISO(e)
49	}
50}
51
52#[cfg(feature = "standards-rfc")]
53crate::impl_error_display!(RFCError {
54	RFC5424Error(e) => "{e}",
55});
56
57#[cfg(feature = "standards-iso")]
58crate::impl_error_display!(ISOError {
59	Message(s) => "ISO error: {s}",
60});
61
62crate::impl_error_display!(StandardError {
63	RFC(e) => "{e}",
64	ISO(e) => "{e}",
65});