use std::fmt::{self, Display, Formatter};
use crate::loader::SourceTrace;
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub struct UnknownField {
pub path: String,
pub source: Option<SourceTrace>,
pub suggestion: Option<String>,
}
impl UnknownField {
#[must_use]
pub fn new(path: impl Into<String>) -> Self {
Self {
path: path.into(),
source: None,
suggestion: None,
}
}
#[must_use]
pub fn with_source(mut self, source: Option<SourceTrace>) -> Self {
self.source = source;
self
}
#[must_use]
pub fn with_suggestion(mut self, suggestion: Option<String>) -> Self {
self.suggestion = suggestion;
self
}
}
impl Display for UnknownField {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "unknown field `{}`", self.path)?;
if let Some(source) = &self.source {
write!(f, " from {source}")?;
}
if let Some(suggestion) = &self.suggestion {
write!(f, "; did you mean `{suggestion}`?")?;
}
Ok(())
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct LineColumn {
pub line: usize,
pub column: usize,
}
impl Display for LineColumn {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "line {}, column {}", self.line, self.column)
}
}