i8051_disassembler/store/
error.rs1use std::fmt;
2
3#[derive(Debug, Clone, PartialEq, Eq)]
4pub struct DslError {
5 pub message: String,
6 pub offset: usize,
7}
8
9impl DslError {
10 pub fn new(offset: usize, message: impl Into<String>) -> Self {
11 Self {
12 message: message.into(),
13 offset,
14 }
15 }
16}
17
18impl fmt::Display for DslError {
19 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
20 write!(f, "dsl parse error at byte {}: {}", self.offset, self.message)
21 }
22}
23
24impl std::error::Error for DslError {}
25
26impl serde::ser::Error for DslError {
27 fn custom<T: fmt::Display>(msg: T) -> Self {
28 Self::new(0, msg.to_string())
29 }
30}
31
32impl serde::de::Error for DslError {
33 fn custom<T: fmt::Display>(msg: T) -> Self {
34 Self::new(0, msg.to_string())
35 }
36}