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
use thiserror::Error;
#[derive(Error, Debug, PartialEq)]
pub enum Error {
#[error("stream is nil")]
ErrNilStream,
#[error("incomplete frame header")]
ErrIncompleteFrameHeader,
#[error("incomplete frame data")]
ErrIncompleteFrameData,
#[error("incomplete file header")]
ErrIncompleteFileHeader,
#[error("IVF signature mismatch")]
ErrSignatureMismatch,
#[error("IVF version unknown, parser may not parse correctly")]
ErrUnknownIVFVersion,
#[error("file not opened")]
ErrFileNotOpened,
#[error("invalid nil packet")]
ErrInvalidNilPacket,
#[error("bad header signature")]
ErrBadIDPageSignature,
#[error("wrong header, expected beginning of stream")]
ErrBadIDPageType,
#[error("payload for id page must be 19 bytes")]
ErrBadIDPageLength,
#[error("bad payload signature")]
ErrBadIDPagePayloadSignature,
#[error("not enough data for payload header")]
ErrShortPageHeader,
#[error("expected and actual checksum do not match")]
ErrChecksumMismatch,
#[allow(non_camel_case_types)]
#[error("{0}")]
new(String),
}
impl Error {
pub fn equal(&self, err: &anyhow::Error) -> bool {
err.downcast_ref::<Self>().map_or(false, |e| e == self)
}
}