1use std::fmt;
2
3pub type Result<T> = std::result::Result<T, RenderError>;
4
5#[derive(Debug)]
6pub enum RenderError {
7 Core(justpdf_core::JustPdfError),
9 InvalidDimensions { detail: String },
11 Image { detail: String },
13 Encode { detail: String },
15 Io(std::io::Error),
17}
18
19impl fmt::Display for RenderError {
20 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21 match self {
22 Self::Core(e) => write!(f, "PDF error: {e}"),
23 Self::InvalidDimensions { detail } => write!(f, "invalid dimensions: {detail}"),
24 Self::Image { detail } => write!(f, "image error: {detail}"),
25 Self::Encode { detail } => write!(f, "encode error: {detail}"),
26 Self::Io(e) => write!(f, "I/O error: {e}"),
27 }
28 }
29}
30
31impl std::error::Error for RenderError {}
32
33impl From<justpdf_core::JustPdfError> for RenderError {
34 fn from(e: justpdf_core::JustPdfError) -> Self {
35 Self::Core(e)
36 }
37}
38
39impl From<std::io::Error> for RenderError {
40 fn from(e: std::io::Error) -> Self {
41 Self::Io(e)
42 }
43}