aldrin_parser/error/
io_error.rs1use super::Error;
2use crate::diag::{Diagnostic, DiagnosticKind, Formatted, Formatter};
3use crate::Parsed;
4
5#[derive(Debug)]
6pub struct IoError {
7 schema_name: String,
8 err: std::io::Error,
9}
10
11impl IoError {
12 pub(crate) fn new<S>(schema_name: S, err: std::io::Error) -> Self
13 where
14 S: Into<String>,
15 {
16 Self {
17 schema_name: schema_name.into(),
18 err,
19 }
20 }
21
22 pub fn io_error(&self) -> &std::io::Error {
23 &self.err
24 }
25}
26
27impl Diagnostic for IoError {
28 fn kind(&self) -> DiagnosticKind {
29 DiagnosticKind::Error
30 }
31
32 fn schema_name(&self) -> &str {
33 &self.schema_name
34 }
35
36 fn format<'a>(&'a self, parsed: &'a Parsed) -> Formatted<'a> {
37 let mut fmt = Formatter::new(self, self.err.to_string());
38
39 if let Some(schema) = parsed.get_schema(&self.schema_name) {
40 fmt.note(format!("tried to read `{}`", schema.path().display()));
41 }
42
43 fmt.format()
44 }
45}
46
47impl From<IoError> for Error {
48 fn from(e: IoError) -> Self {
49 Self::IoError(e)
50 }
51}