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
26
27
28
29
30
31
32
33
#[derive(Debug)]
pub struct BCDConversionError {
description: String
}
impl BCDConversionError {
pub fn new(description: String) -> Self {
Self { description }
}
pub fn new_boxed(description: String) -> Box<Self> {
Box::new(Self::new(description))
}
pub fn new_with_template_description<T>(t: &str, v: T, max: T) -> Self
where T: std::fmt::Display
{
Self::new(format!("Error on {} to bcd, passed in value ({}) exceeds maximum of {}", t, v,max))
}
pub fn description<'self_lt>(&'self_lt self) -> &'self_lt str {
&self.description
}
}
impl std::fmt::Display for BCDConversionError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self)
}
}
impl std::error::Error for BCDConversionError {}