1use thiserror::Error;
6
7#[derive(Error, Debug)]
9pub enum ImageError {
10 #[error("Failed to load image: {0}")]
12 LoadError(String),
13
14 #[error("Failed to save image: {0}")]
16 SaveError(String),
17
18 #[error("Unsupported image format: {0}")]
20 UnsupportedFormat(String),
21
22 #[error("Invalid image dimensions: width={width}, height={height}")]
24 InvalidDimensions { width: u32, height: u32 },
25
26 #[error("Image processing error: {0}")]
28 ProcessingError(String),
29
30 #[error("IO error: {0}")]
32 IoError(#[from] std::io::Error),
33
34 #[error("Image library error: {0}")]
36 ImageLibError(#[from] image::ImageError),
37}
38
39#[derive(Error, Debug)]
41pub enum FontError {
42 #[error("Failed to load font: {0}")]
44 LoadError(String),
45
46 #[error("Font not found: {0}")]
48 NotFound(String),
49
50 #[error("Unsupported font format: {0}")]
52 UnsupportedFormat(String),
53
54 #[error("Font rendering error: {0}")]
56 RenderError(String),
57
58 #[error("Invalid font size: {0}")]
60 InvalidSize(f32),
61
62 #[error("Font-kit error: {0}")]
64 FontKitError(String),
65}
66
67#[derive(Error, Debug)]
69pub enum DrawError {
70 #[error("Invalid color value: {0}")]
72 InvalidColor(String),
73
74 #[error("Invalid coordinates: x={x}, y={y}")]
76 InvalidCoordinates { x: i32, y: i32 },
77
78 #[error("Invalid size: width={width}, height={height}")]
80 InvalidSize { width: u32, height: u32 },
81
82 #[error("Draw operation failed: {0}")]
84 OperationFailed(String),
85
86 #[error(transparent)]
88 ImageError(#[from] ImageError),
89
90 #[error(transparent)]
92 FontError(#[from] FontError),
93}
94
95pub type Result<T> = std::result::Result<T, DrawError>;
97
98pub type ImageResult<T> = std::result::Result<T, ImageError>;
100
101pub type FontResult<T> = std::result::Result<T, FontError>;