Skip to content

Commit

Permalink
Implement std::error::Error for ImageError
Browse files Browse the repository at this point in the history
  • Loading branch information
Orar authored and erwanvivien committed Oct 29, 2023
1 parent f545c17 commit a7aa55a
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/convert/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
//! # }
//! ```
use std::error::Error;
use std::fmt::{Formatter, Write};
use std::io;

use crate::QRCode;
Expand Down Expand Up @@ -52,6 +54,18 @@ pub enum ImageError {
EncodingError(String),
}

impl std::error::Error for ImageError {}

impl std::fmt::Display for ImageError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
ImageError::IoError(io_err) => f.write_str(io_err.to_string().as_str()),
ImageError::ImageError(error) => f.write_str(error.as_str()),
ImageError::EncodingError(error) => f.write_str(error.as_str())
}
}
}

/// Creates an ImageBuilder instance, which contains an [`SvgBuilder`]
impl Default for ImageBuilder {
fn default() -> Self {
Expand Down

0 comments on commit a7aa55a

Please sign in to comment.