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
use std::{error, fmt, result};
#[derive(Debug)]
pub enum Error<Hash: fmt::Debug + fmt::LowerHex> {
AlreadyImported(Hash),
TooCheapToEnter(Hash, String),
TooCheapToReplace(Hash, Hash),
}
pub type Result<T, H> = result::Result<T, Error<H>>;
impl<H: fmt::Debug + fmt::LowerHex> fmt::Display for Error<H> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Error::AlreadyImported(h) => write!(f, "[{:?}] already imported", h),
Error::TooCheapToEnter(hash, min_score) => write!(
f,
"[{:x}] too cheap to enter the pool. Min score: {}",
hash, min_score
),
Error::TooCheapToReplace(old_hash, hash) => {
write!(f, "[{:x}] too cheap to replace: {:x}", hash, old_hash)
}
}
}
}
impl<H: fmt::Debug + fmt::LowerHex> error::Error for Error<H> {}
#[cfg(test)]
impl<H: fmt::Debug + fmt::LowerHex> PartialEq for Error<H>
where
H: PartialEq,
{
fn eq(&self, other: &Self) -> bool {
use self::Error::*;
match (self, other) {
(&AlreadyImported(ref h1), &AlreadyImported(ref h2)) => h1 == h2,
(&TooCheapToEnter(ref h1, ref s1), &TooCheapToEnter(ref h2, ref s2)) => {
h1 == h2 && s1 == s2
}
(&TooCheapToReplace(ref old1, ref new1), &TooCheapToReplace(ref old2, ref new2)) => {
old1 == old2 && new1 == new2
}
_ => false,
}
}
}