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::ops::Deref;
use bincode::ErrorKind;
use thiserror::Error;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Error, Debug)]
pub enum Error {
#[error("Error converting IR to string")]
Format(#[from] std::fmt::Error),
#[error("Unexpected end of bytes. Deserialiser expected more bytes in the decompress slice")]
UnexpectedEndOfBytes,
#[error("Could not deserialize invalid unicode scalar value")]
InvalidUnicodeChar,
#[error("Unexpected bincode error")]
OtherBincode(bincode::Error),
}
impl From<bincode::Error> for Error {
fn from(value: bincode::Error) -> Self {
match value.deref() {
ErrorKind::InvalidCharEncoding => {
Error::InvalidUnicodeChar
}
ErrorKind::SizeLimit => {
Error::UnexpectedEndOfBytes
}
ErrorKind::Io(e) => {
match e.kind() {
std::io::ErrorKind::UnexpectedEof => {
Error::UnexpectedEndOfBytes
}
_ => {
Error::OtherBincode(value)
}
}
}
_ => {
Error::OtherBincode(value)
}
}
}
}