webdav_xml/
error.rs

1// SPDX-FileCopyrightText: d-k-bo <d-k-bo@mailbox.org>
2//
3// SPDX-License-Identifier: MIT OR Apache-2.0
4
5use bytes::Bytes;
6
7/// Alias for the result type that is used in this crate.
8pub type Result<T> = std::result::Result<T, Error>;
9
10/// Error type to wrap all errors that might occur when (de)serializing.
11#[derive(Debug, thiserror::Error)]
12#[non_exhaustive]
13pub enum Error {
14    #[error("unexpected value type: {0}")]
15    InvalidValueType(&'static str),
16    #[error("missing `{0}` element")]
17    MissingElement(&'static str),
18    #[error("empty `{0}` element")]
19    EmptyElement(&'static str),
20    #[error("conflicting elements: {0}")]
21    ConflictingElements(&'static str),
22    #[error("invalid namespace declaration: {0:?}")]
23    InvalidNamespace(Bytes),
24    #[error(transparent)]
25    Xml(#[from] quick_xml::Error),
26    #[error("unexpected tag")]
27    UnexpectedTag,
28    #[error(transparent)]
29    Utf8(#[from] std::str::Utf8Error),
30    #[error(transparent)]
31    Other(#[from] Box<dyn std::error::Error + Send + Sync>),
32}
33
34impl Error {
35    pub fn other(e: impl Into<Box<dyn std::error::Error + Send + Sync>>) -> Self {
36        Self::Other(e.into())
37    }
38}