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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
use std::{fmt::Display, str::Utf8Error, string::FromUtf8Error};
use serde::{de, ser};
use crate::format::Kind;
#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error("not a pot: invalid header")]
NotAPot,
#[error("incompatible version")]
IncompatibleVersion,
#[error("{0}")]
Message(String),
#[error("extra data at end of input")]
TrailingBytes,
#[error("unexpected end of file")]
Eof,
#[error("numerical data cannot fit")]
ImpreciseCastWouldLoseData,
#[error("io error: {0}")]
Io(#[from] std::io::Error),
#[error("serializing sequences of unknown size is unsupported")]
SequenceSizeMustBeKnown,
#[error("invalid utf8: {0}")]
InvalidUtf8(String),
#[error("invalid kind: {0}")]
InvalidKind(u8),
#[error("encountered atom kind {0:?}, expected {1:?}")]
UnexpectedKind(Kind, Kind),
#[error("unknown symbol {0}")]
UnknownSymbol(u64),
#[error("an atom header was incorrectly formatted")]
InvalidAtomHeader,
#[error("the deserialized value is larger than the allowed allocation limit")]
TooManyBytesRead,
}
impl ser::Error for Error {
fn custom<T: Display>(msg: T) -> Self {
Self::Message(msg.to_string())
}
}
impl de::Error for Error {
fn custom<T: Display>(msg: T) -> Self {
Self::Message(msg.to_string())
}
}
impl From<Utf8Error> for Error {
fn from(err: Utf8Error) -> Self {
Self::InvalidUtf8(err.to_string())
}
}
impl From<FromUtf8Error> for Error {
fn from(err: FromUtf8Error) -> Self {
Self::InvalidUtf8(err.to_string())
}
}