zbus_xml/
error.rs
1use quick_xml::de::DeError;
2use static_assertions::assert_impl_all;
3use std::{convert::Infallible, error, fmt};
4use zvariant::Error as VariantError;
5
6#[derive(Clone, Debug)]
10#[non_exhaustive]
11pub enum Error {
12 Variant(VariantError),
13 QuickXml(DeError),
15}
16
17assert_impl_all!(Error: Send, Sync, Unpin);
18
19impl PartialEq for Error {
20 fn eq(&self, other: &Self) -> bool {
21 match (self, other) {
22 (Self::Variant(s), Self::Variant(o)) => s == o,
23 (Self::QuickXml(_), Self::QuickXml(_)) => false,
24 (_, _) => false,
25 }
26 }
27}
28
29impl error::Error for Error {
30 fn source(&self) -> Option<&(dyn error::Error + 'static)> {
31 match self {
32 Error::Variant(e) => Some(e),
33 Error::QuickXml(e) => Some(e),
34 }
35 }
36}
37
38impl fmt::Display for Error {
39 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
40 match self {
41 Error::Variant(e) => write!(f, "{e}"),
42 Error::QuickXml(e) => write!(f, "XML error: {e}"),
43 }
44 }
45}
46
47impl From<VariantError> for Error {
48 fn from(val: VariantError) -> Self {
49 Error::Variant(val)
50 }
51}
52
53impl From<DeError> for Error {
54 fn from(val: DeError) -> Self {
55 Error::QuickXml(val)
56 }
57}
58
59impl From<Infallible> for Error {
60 fn from(i: Infallible) -> Self {
61 match i {}
62 }
63}
64
65pub type Result<T> = std::result::Result<T, Error>;