Skip to main content

subspace_core/config/
notice.rs

1use std::fmt;
2use std::path::PathBuf;
3
4/// A problem in the config file, shown to Zack. `key` is the JSON path of
5/// the value, such as `web.search.endpoint`, or empty for the whole file.
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7pub enum NoticeKind {
8    Warning,
9}
10
11#[derive(Debug, Clone, PartialEq, Eq)]
12pub struct Notice {
13    pub kind: NoticeKind,
14    pub file: PathBuf,
15    pub key: String,
16    pub message: String,
17}
18
19impl fmt::Display for Notice {
20    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21        let file = self.file.display();
22        match self.key.as_str() {
23            "" => write!(f, "{file}: {}", self.message),
24            key => write!(f, "{file}: {key}: {}", self.message),
25        }
26    }
27}