asnfuzzgen_codecs/per/
error.rs1use std::fmt::Display;
4
5#[derive(Debug)]
6pub struct Error {
7 msg: String,
8 context: Vec<String>,
9}
10
11impl Error {
12 pub fn new<T: AsRef<str> + Display>(msg: T) -> Self {
13 Error {
14 msg: msg.to_string(),
15 context: Vec::new(),
16 }
17 }
18 pub fn push_context(&mut self, context_elem: &str) {
19 self.context.push(context_elem.to_string());
20 }
21}
22impl std::fmt::Display for Error {
23 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
24 if self.context.is_empty() {
25 write!(f, "{}", self.msg)
26 } else {
27 write!(f, "[{}]:{}", self.context.join("."), self.msg)
28 }
29 }
30}
31
32impl std::error::Error for Error {}