bcd_numbers/
error.rs

1#[derive(Debug)]
2pub struct BCDConversionError {
3    description: String
4}
5
6impl BCDConversionError {
7    pub fn new(description: impl Into<String>) -> Self {
8        Self { description: description.into() }
9    }
10
11    pub fn new_boxed(description: String) -> Box<Self> {
12        Box::new(Self::new(description))
13    }
14
15    pub fn new_with_template_description<T>(t: &str, v: T, max: T) -> Self 
16        where T: std::fmt::Display
17    {
18        Self::new(format!("Error on {} to bcd, passed in value ({}) exceeds maximum of {}", t, v,max))
19    }
20
21    pub fn description<'self_lt>(&'self_lt self) -> &'self_lt str {
22        &self.description
23    }
24}
25
26impl std::fmt::Display for BCDConversionError {
27    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
28        write!(f, "{:?}", self)
29    }
30}
31
32impl std::error::Error for BCDConversionError {}
33