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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use std::fmt::Display;
use crate::encoding::FromBytes;
#[derive(Debug)]
pub struct ProtocolError {}
#[derive(Debug)]
pub struct ParsingError {}
#[derive(Debug)]
pub struct RemoteException {
pub cause: String
}
#[derive(Debug)]
pub struct UserError<T: std::fmt::Display> {
pub exception: T
}
impl std::fmt::Display for ProtocolError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "ProtocolError!")
}
}
impl std::fmt::Display for ParsingError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "ParsingError!")
}
}
impl std::fmt::Display for RemoteException {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "RemoteException: {}", self.cause)
}
}
impl<T: Display> std::fmt::Display for UserError<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.exception)
}
}
impl std::error::Error for ProtocolError {}
impl std::error::Error for ParsingError {}
impl std::error::Error for RemoteException {}
impl<T: std::fmt::Debug + Display + FromBytes> std::error::Error for UserError<T> {}
impl FromBytes for ProtocolError {
fn from_bytes(_bytes: &[u8], _read_bytes: &mut i32) -> Result<Self, Box<dyn std::error::Error>> where Self: Sized {
Ok(ProtocolError {})
}
}