nyar_error/errors/
convert.rs

1use super::*;
2use crate::parsing::ForeignInterfaceError;
3
4impl From<ForeignInterfaceError> for NyarError {
5    fn from(value: ForeignInterfaceError) -> Self {
6        Self { kind: Box::new(NyarErrorKind::Parsing(value.into())), level: value.into() }
7    }
8}
9
10impl Into<SyntaxError> for ForeignInterfaceError {
11    fn into(self) -> SyntaxError {
12        match self {
13            Self::MissingForeignMark { span } => {
14                SyntaxError::new("foreign mark not found".to_string()).with_hint("missing hint 3").with_span(span)
15            }
16            Self::MissingForeignFlag { kind, hint, span } => SyntaxError::new(format!("foreign {kind} must mark as `{hint}`"))
17                .with_hint(format!("add `{hint}` modifier before declaration"))
18                .with_span(span),
19            Self::InvalidForeignModule { span } => {
20                SyntaxError::new("foreign module not found".to_string()).with_hint("missing hint 1").with_span(span)
21            }
22            Self::InvalidForeignName { span } => {
23                SyntaxError::new("foreign name not found".to_string()).with_hint("missing hint 2").with_span(span)
24            }
25        }
26    }
27}
28
29impl Into<ReportKind> for ForeignInterfaceError {
30    fn into(self) -> ReportKind {
31        match self {
32            Self::MissingForeignMark { .. } => ReportKind::Trace,
33            Self::MissingForeignFlag { .. } => ReportKind::Alert,
34            Self::InvalidForeignModule { .. } => ReportKind::Error,
35            Self::InvalidForeignName { .. } => ReportKind::Error,
36        }
37    }
38}