pixiv_api/errors/
mod.rs

1use std::fmt::{Debug, Formatter};
2use std::error::Error;
3use std::fmt::Display;
4use std::path::PathBuf;
5
6mod display;
7mod convert;
8
9/// The result type of this crate.
10pub type Result<T> = std::result::Result<T, PixivError>;
11
12/// A boxed error kind, wrapping an [ExampleErrorKind].
13#[derive(Clone)]
14pub struct PixivError {
15    kind: Box<ExampleErrorKind>,
16}
17
18/// The kind of [PixivError].
19#[derive(Debug, Clone)]
20pub enum ExampleErrorKind {
21    IoError {
22        message: String,
23        file: PathBuf,
24    },
25    RequestError {
26        /// The message of the error.
27        message: String,
28        context: String,
29    },
30    /// An unknown error.
31    UnknownError,
32}
33
34
35impl PixivError {
36    pub fn request_error(message: impl Into<String>, context: impl Into<String>) -> Self {
37        Self {
38            kind: Box::new(ExampleErrorKind::RequestError {
39                message: message.into(),
40                context: context.into(),
41            }),
42        }
43    }
44}