use serde::Serialize;
use std::fmt;
use std::str::FromStr;
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, Serialize)]
pub enum IssueKind {
Duplicate,
Empty,
Missing,
NotDirectory,
Unreadable,
SuspiciousOrder,
ShadowedCommand,
Unwanted,
}
impl IssueKind {
pub const SUPPORTED_VALUES: &'static str = "duplicate, empty, missing, not_directory, unreadable, suspicious_order, shadowed_command, unwanted";
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
Self::Duplicate => "duplicate",
Self::Empty => "empty",
Self::Missing => "missing",
Self::NotDirectory => "not_directory",
Self::Unreadable => "unreadable",
Self::SuspiciousOrder => "suspicious_order",
Self::ShadowedCommand => "shadowed_command",
Self::Unwanted => "unwanted",
}
}
}
impl FromStr for IssueKind {
type Err = ParseIssueKindError;
fn from_str(value: &str) -> Result<Self, Self::Err> {
match value {
"duplicate" => Ok(Self::Duplicate),
"empty" => Ok(Self::Empty),
"missing" => Ok(Self::Missing),
"not_directory" => Ok(Self::NotDirectory),
"unreadable" => Ok(Self::Unreadable),
"suspicious_order" => Ok(Self::SuspiciousOrder),
"shadowed_command" => Ok(Self::ShadowedCommand),
"unwanted" => Ok(Self::Unwanted),
_ => Err(ParseIssueKindError),
}
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct ParseIssueKindError;
impl fmt::Display for ParseIssueKindError {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
formatter,
"expected one of: {}",
IssueKind::SUPPORTED_VALUES
)
}
}
impl std::error::Error for ParseIssueKindError {}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct Diagnostic {
pub kind: IssueKind,
pub message: String,
pub entry_index: Option<usize>,
pub entry_value: Option<String>,
pub related_indexes: Vec<usize>,
}