1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
use std::fmt;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Error {
pub message: String,
pub position: usize,
}
impl Error {
pub fn new(message: impl Into<String>, position: usize) -> Error {
Error {message: message.into(), position}
}
}
impl fmt::Display for Error {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
write!(formatter, "{} (at character {})", self.message, self.position + 1)
}
}
impl std::error::Error for Error {}