use std::fmt;
use std::io;
use std::path::{Path, PathBuf};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ScanIssue {
path: PathBuf,
kind: io::ErrorKind,
message: String,
}
impl ScanIssue {
pub fn new(path: impl Into<PathBuf>, kind: io::ErrorKind, message: impl Into<String>) -> Self {
Self {
path: path.into(),
kind,
message: message.into(),
}
}
pub fn path(&self) -> &Path {
&self.path
}
pub fn kind(&self) -> io::ErrorKind {
self.kind
}
pub fn message(&self) -> &str {
&self.message
}
}
impl fmt::Display for ScanIssue {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"scan failed at {}: {}",
self.path.display(),
self.message
)
}
}
impl std::error::Error for ScanIssue {}
impl From<swdir::ScanError> for ScanIssue {
fn from(err: swdir::ScanError) -> Self {
let path = err.path().to_path_buf();
let kind = err.io_kind();
let message = err.to_string();
Self {
path,
kind,
message,
}
}
}