1#![forbid(unsafe_code)]
2#![cfg_attr(ci_, deny(warnings))]
3#![cfg_attr(all(test, feature = "bench"), feature(test))]
4#![cfg_attr(not(feature = "std"), no_std)]
5#[cfg(feature = "alloc")]
8extern crate alloc;
9
10macro_rules! error {
11 ($name:ident $(($source:ident($x:expr) $(, $other:ident)*))? $(, $variant:ident)*) => {
12 #[cfg(feature = "std")]
13 impl ::std::error::Error for $name {
14 fn source(&self) -> Option<&(dyn ::std::error::Error + 'static)> {
15 match self {
16 $($name($source $(, $other)*) => Some($x),)?
17 $($name::$variant(s) => Some(s),)*
18
19 #[allow(unreachable_patterns)]
20 _ => None,
21 }
22 }
23 }
24 };
25}
26
27#[macro_export]
30#[doc(hidden)]
31macro_rules! declare_any_error {
32 (@real ($($variant:ident $ty:ty,)+)) => {
33 #[derive(Debug)]
34 pub enum AnyError {
35 $($variant($ty),)+
36 }
37
38 $(impl From<$ty> for AnyError {
39 fn from(e: $ty) -> Self { Self::$variant(e) }
40 })+
41 };
42
43 (@real ($($done:tt)*) ($($path:tt)+)($name:ident), $($rest:tt)*) => {
44 $crate::declare_any_error!(@real ($($done)* $name $($path)+::$name,) $($rest)*);
45 };
46
47 (@real ($($done:tt)*) ($($path:tt)+)($name:ident) as $variant:ident, $($rest:tt)*) => {
48 $crate::declare_any_error!(@real ($($done)* $variant $($path)+::$name,) $($rest)*);
49 };
50
51 ($name:ident) => {
52 $crate::declare_any_error!(
53 @real ()
54 (::core::convert)(Infallible),
55 ($crate::view)(BoundsError),
56 ($crate::view)(MessageError),
57 ($crate::view)(QuestionError),
58 ($crate::view)(RecordError),
59 ($crate::view)(NameError),
60 ($crate::view)(LabelError),
61 ($crate::view)(ExtensionError),
62 ($crate::view::rdata)(RdataError),
63 ($crate::view::rdata)(SoaError),
64 ($crate::emit)(SinkError),
65 ($crate::emit)(GrowError),
66 ($crate::emit::extension)(ExtensionError) as EmitExtensionError,
67 ($crate::emit::message)(MessageError) as EmitMessageError,
68 ($crate::emit::name)(NameError) as EmitNameError,
69 ($crate::emit::question)(QuestionError) as EmitQuestionError,
70 ($crate::emit::record)(RecordError) as EmitRecordError,
71 ($crate::core)(TypeFromStrError),
72 ($crate::core)(ClassFromStrError),
73 ($crate::core)(TtlFromStrError),
74 (::core::fmt)(Error),
75 );
76 };
77}
78
79pub mod r#const;
80pub mod core;
81pub mod emit;
82pub mod view;
83pub mod zone;
84
85mod seen;