use std::error::Error as StdError;
use std::fmt;
use std::fmt::Debug;
use std::io;
#[derive(Debug)]
pub enum SerdeVaultError {
IoError(io::Error),
SerializationError(String),
DeserializationError(String),
EncryptionError(String),
DecryptionError(String),
PasswordError(String),
RandomError(String), }
impl From<io::Error> for SerdeVaultError {
fn from(error: io::Error) -> Self {
SerdeVaultError::IoError(error)
}
}
impl fmt::Display for SerdeVaultError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
SerdeVaultError::IoError(e) => write!(f, "I/O error: {}", e),
SerdeVaultError::SerializationError(e) => write!(f, "Serialization error: {}", e),
SerdeVaultError::DeserializationError(e) => write!(f, "Deserialization error: {}", e),
SerdeVaultError::EncryptionError(e) => write!(f, "Encryption error: {}", e),
SerdeVaultError::DecryptionError(e) => write!(f, "Decryption error: {}", e),
SerdeVaultError::PasswordError(e) => write!(f, "Password error: {}", e),
SerdeVaultError::RandomError(_) => todo!(),
}
}
}
impl StdError for SerdeVaultError {
fn source(&self) -> Option<&(dyn StdError + 'static)> {
match self {
SerdeVaultError::IoError(e) => Some(e),
_ => None,
}
}
}