1use std::{fmt,io};
2use std::error::Error;
3
4#[derive(Debug)]
6#[derive(PartialEq)]
7pub struct ScanError {
8 pub details: String,
9 pub lineno: u32,
10}
11
12impl fmt::Display for ScanError {
13 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
14 write!(f,"line {}: {}",self.lineno,self.details)
15 }
16}
17
18impl ScanError {
19 pub fn new(msg: &str) -> ScanError {
21 ScanError{details: msg.into(), lineno: 1}
22 }
23}
24
25impl Error for ScanError {}
26
27impl From<io::Error> for ScanError {
28 fn from(err: io::Error) -> ScanError {
29 ScanError::new(&err.to_string())
30 }
31}