visual_cryptography/
error.rs1use std::{error::Error, fmt};
4
5pub type Result<T> = std::result::Result<T, VCError>;
7
8#[derive(Debug)]
10pub enum VCError {
11    InvalidConfiguration(String),
13    InsufficientShares { required: usize, provided: usize },
15    DecryptionError(String),
17    CoverImageError(String),
19    ImageError(String),
21    MatrixError(String),
23    QrCodeError(String),
25}
26
27impl fmt::Display for VCError {
28    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
29        match self {
30            VCError::InvalidConfiguration(msg) => write!(f, "Invalid configuration: {}", msg),
31            VCError::InsufficientShares { required, provided } => {
32                write!(
33                    f,
34                    "Insufficient shares: required {}, provided {}",
35                    required, provided
36                )
37            }
38            VCError::DecryptionError(msg) => write!(f, "Decryption error: {}", msg),
39            VCError::CoverImageError(msg) => write!(f, "Cover image error: {}", msg),
40            VCError::ImageError(msg) => write!(f, "Image error: {}", msg),
41            VCError::MatrixError(msg) => write!(f, "Matrix error: {}", msg),
42            VCError::QrCodeError(msg) => write!(f, "QR code error: {}", msg),
43        }
44    }
45}
46
47impl Error for VCError {}
48
49impl From<image::ImageError> for VCError {
50    fn from(err: image::ImageError) -> Self {
51        VCError::ImageError(err.to_string())
52    }
53}