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
77
78
79
80
81
82
83
84
85
86
87
88
89
use thiserror::Error;
use crate::ffi;
#[derive(Debug, Error, PartialEq, Eq)]
pub enum Error {
#[error("A parameter passed to this function was invalid.")]
Invalid,
#[error("A memory allocation failed.")]
NoMem,
#[error("The engine was terminated by callback.")]
ScanTerminated,
#[cfg(feature = "compile")]
#[error("The pattern compiler failed with more detail, {0}.")]
CompileError(crate::compile::Error),
#[error("The given database was built for a different version of Hyperscan.")]
DbVersionError,
#[error("The given database was built for a different platform (i.e., CPU type).")]
DbPlatformError,
#[error("The given database was built for a different mode of operation.")]
DbModeError,
#[error("A parameter passed to this function was not correctly aligned.")]
BadAlign,
#[error("The memory allocator did not correctly return memory suitably aligned.")]
BadAlloc,
#[error("The scratch region was already in use.")]
ScratchInUse,
#[error("Unsupported CPU architecture.")]
ArchError,
#[error("Provided buffer was too small.")]
InsufficientSpace,
#[cfg(feature = "v5")]
#[error("Unexpected internal error.")]
UnknownError,
#[error("Unknown error code: {0}")]
Code(ffi::hs_error_t),
}
impl From<ffi::hs_error_t> for Error {
fn from(err: ffi::hs_error_t) -> Self {
use Error::*;
match err {
ffi::HS_INVALID => Invalid,
ffi::HS_NOMEM => NoMem,
ffi::HS_SCAN_TERMINATED => ScanTerminated,
ffi::HS_DB_VERSION_ERROR => DbVersionError,
ffi::HS_DB_PLATFORM_ERROR => DbPlatformError,
ffi::HS_DB_MODE_ERROR => DbModeError,
ffi::HS_BAD_ALIGN => BadAlign,
ffi::HS_BAD_ALLOC => BadAlloc,
ffi::HS_SCRATCH_IN_USE => ScratchInUse,
ffi::HS_ARCH_ERROR => ArchError,
ffi::HS_INSUFFICIENT_SPACE => InsufficientSpace,
#[cfg(feature = "v5")]
ffi::HS_UNKNOWN_ERROR => UnknownError,
_ => Code(err),
}
}
}