1use std::hash::{Hash, Hasher};
2
3use num_enum::TryFromPrimitiveError;
4use thiserror::Error;
5
6use neo3::prelude::OpCode;
7
8#[derive(Error, Debug, PartialEq, Eq, Clone)]
9pub enum CodecError {
10 #[error("Invalid passphrase: {0}")]
11 InvalidPassphrase(String),
12 #[error("Invalid format")]
13 InvalidFormat,
14 #[error("Index out of bounds: {0}")]
15 IndexOutOfBounds(String),
16 #[error("Invalid encoding: {0}")]
17 InvalidEncoding(String),
18 #[error("Invalid op code")]
19 InvalidOpCode,
20 #[error(transparent)]
21 TryFromPrimitiveError(#[from] TryFromPrimitiveError<OpCode>),
22}
23
24impl Hash for CodecError {
25 fn hash<H: Hasher>(&self, state: &mut H) {
26 match self {
27 CodecError::InvalidPassphrase(s) => {
28 0.hash(state);
29 s.hash(state);
30 },
31 CodecError::InvalidFormat => 1.hash(state),
32 CodecError::IndexOutOfBounds(s) => {
33 2.hash(state);
34 s.hash(state);
35 },
36 CodecError::InvalidEncoding(s) => {
37 3.hash(state);
38 s.hash(state);
39 },
40 CodecError::InvalidOpCode => 4.hash(state),
41 CodecError::TryFromPrimitiveError(_) => 5.hash(state),
42 }
43 }
44}