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
34
use thiserror::Error;
pub type Result<T> = std::result::Result<T, ProtocolError>;
#[derive(Debug, Error, Clone)]
pub struct ProtocolError(pub &'static str);
impl ProtocolError {
pub fn coerce_static_from_str(error_str: &str) -> Self {
let coerce_static = Box::leak(error_str.to_string().into_boxed_str());
ProtocolError(coerce_static)
}
}
impl std::fmt::Display for ProtocolError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
use bigdecimal::ParseBigDecimalError;
impl From<ParseBigDecimalError> for ProtocolError {
fn from(_err: ParseBigDecimalError) -> Self {
ProtocolError("Error converting to BigDecimal")
}
}