Skip to main content

pdfkit/
error.rs

1use std::error::Error;
2use std::fmt;
3
4pub type Result<T> = std::result::Result<T, PdfKitError>;
5
6#[derive(Debug, Clone, PartialEq, Eq)]
7pub struct PdfKitError {
8    code: i32,
9    message: String,
10}
11
12impl PdfKitError {
13    pub(crate) fn new(code: i32, message: impl Into<String>) -> Self {
14        Self {
15            code,
16            message: message.into(),
17        }
18    }
19
20    #[must_use]
21    pub fn code(&self) -> i32 {
22        self.code
23    }
24
25    #[must_use]
26    pub fn message(&self) -> &str {
27        &self.message
28    }
29}
30
31impl fmt::Display for PdfKitError {
32    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
33        write!(f, "{} (status {})", self.message, self.code)
34    }
35}
36
37impl Error for PdfKitError {}