Skip to main content

devpage_core/
problem.rs

1//! A problem: one broken thing a document holds, where it was found — the
2//! value link checking, the navbar, widgets and comments report, and the page
3//! lists above itself. A leaf: it depends on nothing else in devpage.
4
5/// One broken thing, where it was found.
6#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize)]
7pub struct Problem {
8    /// The file it is in, from the top of the served folder.
9    pub file: String,
10    /// The line it is on, counted from 1 — `None` when it is about the whole
11    /// file.
12    #[serde(skip_serializing_if = "Option::is_none")]
13    pub line: Option<usize>,
14    /// The column on `line`, where the problem names one: a design's.
15    #[serde(skip_serializing_if = "Option::is_none")]
16    pub column: Option<usize>,
17    /// What is broken, for a reader.
18    pub message: String,
19    /// The link as written, so the page can mark it where it stands.
20    #[serde(skip_serializing_if = "Option::is_none")]
21    pub target: Option<String>,
22}
23
24impl std::fmt::Display for Problem {
25    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
26        match (self.line, self.column) {
27            (Some(line), Some(column)) => {
28                write!(f, "{}:{line}:{column}: {}", self.file, self.message)
29            }
30            (Some(line), None) => write!(f, "{}:{line}: {}", self.file, self.message),
31            _ => write!(f, "{}: {}", self.file, self.message),
32        }
33    }
34}