walker_common/retrieve/
error.rs

1use crate::{source::Source, utils::url::Urlify};
2use std::fmt::Debug;
3use url::Url;
4
5/// An error from a retrieval visitor.
6#[derive(Clone, Debug, thiserror::Error)]
7pub enum RetrievalError<D, S>
8where
9    D: Urlify,
10    S: Source,
11{
12    /// Failed to fetch the discovered document from the source.
13    #[error("source error: {err}")]
14    Source { err: S::Error, discovered: D },
15}
16
17impl<D, S> RetrievalError<D, S>
18where
19    D: Urlify,
20    S: Source,
21{
22    pub fn discovered(&self) -> &D {
23        match self {
24            Self::Source { discovered, .. } => discovered,
25        }
26    }
27}
28
29impl<S, D> Urlify for RetrievalError<D, S>
30where
31    D: Urlify,
32    S: Source,
33{
34    fn url(&self) -> &Url {
35        match self {
36            Self::Source { discovered, .. } => discovered.url(),
37        }
38    }
39}