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
#![allow(missing_docs)]
use std::fmt;
#[derive(Debug)]
pub enum Error {
NoCommonSubstrings,
MalformedInput,
BlockSizeParse,
IncompatibleBlockSizes,
TooManyBlocks,
InvalidHashString(std::string::FromUtf8Error),
}
impl std::error::Error for Error {
fn description(&self) -> &str {
match self {
Error::NoCommonSubstrings => "No common substrings were found between two fuzzy hashes",
Error::MalformedInput => "Strings are not in proper fuzzy hash format",
Error::BlockSizeParse => "Could not parse block sizes in string(s)",
Error::IncompatibleBlockSizes => "Fuzzy hashes have incompatible block sizes",
Error::TooManyBlocks => "Total number of blocks exceeds limit",
Error::InvalidHashString(_) => "Unable to produce a valid hash string",
}
}
fn cause(&self) -> Option<&dyn std::error::Error> {
match self {
Error::InvalidHashString(e) => Some(e),
_ => None,
}
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Error processing fuzzy hash(es)")
}
}