Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement std::error::Error for ImageError #44

Merged
merged 1 commit into from
Oct 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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