use std::fmt::{self, Display};
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum StyleDiagnosticCode {
EmptyQueryName,
EmptyReportLabel,
EmptySourceEndpoint,
}
impl Display for StyleDiagnosticCode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let label = match self {
Self::EmptyQueryName => "empty query name",
Self::EmptyReportLabel => "empty report label",
Self::EmptySourceEndpoint => "empty source endpoint",
};
f.write_str(label)
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct StyleDiagnostic {
code: StyleDiagnosticCode,
message: &'static str,
}
impl StyleDiagnostic {
#[must_use]
pub const fn new(code: StyleDiagnosticCode, message: &'static str) -> Self {
Self { code, message }
}
#[must_use]
pub const fn empty_query_name() -> Self {
Self::new(
StyleDiagnosticCode::EmptyQueryName,
"query name must not be empty",
)
}
#[must_use]
pub const fn empty_report_label() -> Self {
Self::new(
StyleDiagnosticCode::EmptyReportLabel,
"report label must not be empty",
)
}
#[must_use]
pub const fn empty_source_endpoint() -> Self {
Self::new(
StyleDiagnosticCode::EmptySourceEndpoint,
"source endpoint must not be empty",
)
}
#[must_use]
pub const fn code(&self) -> StyleDiagnosticCode {
self.code
}
#[must_use]
pub const fn message(&self) -> &'static str {
self.message
}
}
impl Display for StyleDiagnostic {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}: {}", self.code, self.message)
}
}
impl std::error::Error for StyleDiagnostic {}