qr_rs_lib/
error.rs

1use image::ImageError;
2use thiserror::Error;
3
4#[derive(Error, Debug, PartialEq, Eq)]
5pub enum Error {
6  /// Represents invalid parameters (such as a really big size or an empty link).
7  #[error("{0}")]
8  InputError(String),
9
10  /// Represents an error in the QR Code generation. If this happens there's likely a bug in this
11  /// crate.
12  #[error("{0}")]
13  QrError(String),
14
15  /// Represents an error in the encoding of the image. If this happens there's likely a bug
16  /// in this crate.
17  #[error("{0}")]
18  ImageError(String),
19}
20
21impl From<fast_qr::qr::QRCodeError> for Error {
22  fn from(e: fast_qr::qr::QRCodeError) -> Self {
23    match e {
24      fast_qr::qr::QRCodeError::EncodedData => {
25        Self::QrError("Data if too big to be encoded".to_owned())
26      }
27      fast_qr::qr::QRCodeError::SpecifiedVersion => {
28        Self::QrError("Specified version too small to contain data".to_owned())
29      }
30    }
31  }
32}
33
34impl From<png::EncodingError> for Error {
35  fn from(e: png::EncodingError) -> Self {
36    Self::ImageError(e.to_string())
37  }
38}
39
40impl From<ImageError> for Error {
41  fn from(e: ImageError) -> Self {
42    Self::ImageError(e.to_string())
43  }
44}