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 $(($($before:ident, )* [$source:ident: $x:expr] $(, $after:ident)*))? $(, $variant:ident)*) => {
12 impl ::core::error::Error for $name {
13 fn source(&self) -> Option<&(dyn ::core::error::Error + 'static)> {
14 match self {
15 $($name($($before, )* $source $(, $after)*) => Some($x),)?
16 $($name::$variant(s) => Some(s),)*
17
18 #[allow(unreachable_patterns)]
19 _ => None,
20 }
21 }
22 }
23 };
24}
25
26#[macro_export]
31#[doc(hidden)]
32macro_rules! declare_any_error {
33 (@real ($($(#[$meta:meta])* $variant:ident $ty:ty,)+)) => {
34 #[derive(Debug)]
35 #[allow(unused)]
36 pub enum AnyError {
37 $($(#[$meta])* $variant($ty),)+
38 }
39
40 $(
41 $(#[$meta])*
42 impl From<$ty> for AnyError {
43 fn from(e: $ty) -> Self { Self::$variant(e) }
44 }
45 )+
46 };
47
48 (@real ($($done:tt)*) $(#[$meta:meta])* ($($path:tt)+)($name:ident), $($rest:tt)*) => {
49 $crate::declare_any_error!(@real ($($done)* $(#[$meta])* $name $($path)+::$name,) $($rest)*);
50 };
51
52 (@real ($($done:tt)*) $(#[$meta:meta])* ($($path:tt)+)($name:ident) as $variant:ident, $($rest:tt)*) => {
53 $crate::declare_any_error!(@real ($($done)* $(#[$meta])* $variant $($path)+::$name,) $($rest)*);
54 };
55
56 ($name:ident) => {
57 $crate::declare_any_error!(
58 @real ()
59 (::core::convert)(Infallible),
60 ($crate::view)(BoundsError),
61 ($crate::view)(MessageError),
62 ($crate::view)(QuestionError),
63 ($crate::view)(RecordError),
64 ($crate::view)(NameError),
65 ($crate::view)(LabelError),
66 ($crate::view)(ExtensionError),
67 ($crate::emit)(SinkError),
68 ($crate::emit)(GrowError),
69 ($crate::emit::extension)(ExtensionError) as EmitExtensionError,
70 ($crate::emit::message)(MessageError) as EmitMessageError,
71 ($crate::emit::name)(NameError) as EmitNameError,
72 ($crate::emit::question)(QuestionError) as EmitQuestionError,
73 ($crate::emit::record)(RecordError) as EmitRecordError,
74 ($crate::core)(OpcodeRangeError),
75 ($crate::core)(RcodeRangeError),
76 ($crate::core)(TypeFromStrError),
77 ($crate::core)(ClassFromStrError),
78 ($crate::core)(TtlFromStrError),
79 ($crate::name)(OwnedNameError),
80 ($crate::rdata::view::error)(RdataError),
81 ($crate::rdata::view::error)(SoaError),
82 ($crate::rdata::view::error)(TypedRdataError),
83 ($crate::server)(ResponseError),
84 (::core::fmt)(Error),
85 );
86 };
87}
88
89#[macro_use]
90pub mod core;
91pub mod emit;
92pub mod fmt;
93pub mod name;
94pub mod rdata;
95pub mod server;
96pub mod view;
97
98mod seen;
99
100pub const MAX_SUPPORTED_EDNS_VERSION: u8 = 0;