1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/// Error type for this library
#[derive(Debug, thiserror::Error)]
pub enum Error {
    #[error(transparent)]
    Reqwest(#[from] reqwest::Error),

    /// Json parse error
    #[error("failed to parse json")]
    Json {
        /// The data that was being parsed
        data: Box<str>,

        /// The parse error
        #[source]
        error: serde_json::Error,
    },

    /// Failed to find subreddit
    #[error("failed to locate the subreddit")]
    SubredditNotFound,
}

impl Error {
    /// Returns `true` if the error type is `SubredditNotFound`, `false` otherwise.
    pub fn is_subreddit_not_found(&self) -> bool {
        matches!(self, Self::SubredditNotFound)
    }
}