use std::error::Error;
use std::fmt;
#[derive(Debug)]
pub struct KeyRegistryError {
pub context: String,
pub source: Option<Box<dyn Error + Send>>,
}
impl Error for KeyRegistryError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
if let Some(ref err) = self.source {
Some(&**err)
} else {
None
}
}
}
impl fmt::Display for KeyRegistryError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if let Some(ref err) = self.source {
write!(f, "{}: {}", self.context, err)
} else {
f.write_str(&self.context)
}
}
}
#[derive(Debug)]
pub struct KeyPermissionError {
pub context: String,
pub source: Option<Box<dyn Error>>,
}
impl std::error::Error for KeyPermissionError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
if let Some(ref err) = self.source {
Some(&**err)
} else {
None
}
}
}
impl std::fmt::Display for KeyPermissionError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
if let Some(ref err) = self.source {
write!(f, "{}: {}", self.context, err)
} else {
f.write_str(&self.context)
}
}
}