aldrin_parser/error/
invalid_schema_name.rs

1use super::Error;
2use crate::diag::{Diagnostic, DiagnosticKind, Formatted, Formatter};
3use crate::Parsed;
4
5#[derive(Debug)]
6pub struct InvalidSchemaName {
7    schema_name: String,
8}
9
10impl InvalidSchemaName {
11    pub(crate) fn new<S>(schema_name: S) -> Self
12    where
13        S: Into<String>,
14    {
15        Self {
16            schema_name: schema_name.into(),
17        }
18    }
19}
20
21impl Diagnostic for InvalidSchemaName {
22    fn kind(&self) -> DiagnosticKind {
23        DiagnosticKind::Error
24    }
25
26    fn schema_name(&self) -> &str {
27        &self.schema_name
28    }
29
30    fn format<'a>(&'a self, _parsed: &'a Parsed) -> Formatted<'a> {
31        let mut fmt = Formatter::new(self, format!("invalid schema name `{}`", self.schema_name));
32
33        fmt.note("schema names are parsed from the file name");
34        if self.schema_name.contains('-') {
35            fmt.note("hyphens `-` are not allowed in schema names");
36        }
37
38        fmt.format()
39    }
40}
41
42impl From<InvalidSchemaName> for Error {
43    fn from(e: InvalidSchemaName) -> Self {
44        Self::InvalidSchemaName(e)
45    }
46}