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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/* Copyright 2022-2023 Danny McClanahan */
/* SPDX-License-Identifier: BSD-3-Clause */
//! Wrapper for the vectorscan C regex library.
//!
//! # Quirks
//! The [vectorscan] library (originally [hyperscan], from Intel) supports
//! high-performance pattern matching using a subset of PCRE syntax. It was
//! originally written for extremely low-latency network traffic monitoring, so
//! it has some interface quirks that may be unfamiliar:
//! - **[Vectorscan Callback API]:** Matches are "returned" to the user when
//! vectorscan executes a user-provided C ABI method call, so overlapping
//! matches and other interactive feedback with the matching engine are much
//! easier to support compared to a synchronous method call.
//! - **Highly Expressive Pattern Set Matching:** [`expression::ExpressionSet`]
//! supports the full range of searching and matching operations available to
//! individual [`expression::Expression`] instances. This is rare: most other
//! regex engines e.g. do not support finding match offsets, but instead only
//! which expressions in a set matched.
//! - **[Mutable State and String Searching]:** Vectorscan requires the user to
//! explicitly provide a "scratch" space with [`state::Scratch`] to each
//! search method. This state is not very large, but most other regex engines
//! attempt to present an interface without any mutable state, even if
//! internally they use constructions like lazy DFAs.
//!
//! [vectorscan]: https://github.com/VectorCamp/vectorscan
//! [hyperscan]: https://github.com/intel/hyperscan
//! [Vectorscan Callback API]: crate::matchers#vectorscan-callback-api
//! [Highly Expressive Pattern Set Matching]: crate::expression
//! [Mutable State and String Searching]: crate::state#mutable-state-and-string-searching
//!
//! # Feature Flags
//! This library uses [`spack-rs`](https://docs.rs/spack-rs) to configure the build of the
//! vectorscan codebase using [`spack`](https://spack.io), so it can be precise about which native
//! dependencies it brings in:
//! - **`"static"` (default):** link against vectorscan statically. Conflicts
//! with `"dynamic"`.
//! - **`"dynamic"`:** link against vectorscan dynamically. Conflicts with
//! `"static"`, `"chimera"`, and `"alloc"`. Because of `spack`'s caching and
//! RPATH rewriting, the same dynamic library can be shared by every
//! dependency of this crate.
//! - **`"compiler"` (default):** whether to bring in the entire `libhs`
//! library, or just `libhs_runtime`, which is unable to [compile patterns]
//! but can [deserialize them]. This significantly reduces the size of the
//! code added to the binary.
//! - **`"chimera"`:** whether to link against PCRE and add in extra vectorscan
//! code to provide the chimera PCRE compatible search library. Conflicts with
//! `"dynamic"` and requires `"compiler"`.
//!
//! [compile patterns]: crate::database::Database::compile
//! [deserialize them]: crate::database::SerializedDb::deserialize_db
//!
//! Feature flags are also used to gate certain functionality to minimize
//! external dependencies when not in use:
//! - **`"alloc"`:** hook into vectorscan's dynamic memory allocation with
//! [`crate::alloc`]. Requires `"static"` due to modifying process-global
//! hooks.
//! - **`"stream"` (default):** supports stream parsing with [`crate::stream`].
//! - **`"vectored"` (default):** supports vectored mode parsing with
//! [`Mode::VECTORED`].
//! - **`"catch-unwind"` (default):** catches Rust panics in the match callback
//! before they bubble back up to vectorscan to produce undefined behavior.
//! - **`"async"`:** provides an `async` interface over vectorscan's quirky
//! callback API using [`tokio`] as described in [Asynchronous String
//! Scanning].
//! - **`"tokio-impls"`:** implements [`tokio::io::AsyncWrite`] for stream
//! parsers in [`crate::stream::channel::AsyncStreamWriter`].
//!
//! [Asynchronous String Scanning]: crate::state::Scratch#asynchronous-string-scanning
//! [`Mode::VECTORED`]: crate::flags::Mode::VECTORED
/* Warn for missing docs in general, and hard require crate-level docs. */
/* Make all doctests fail if they produce any warnings. */
/* Generate docs.rs info for feature switches. */
pub use hs;
unsafe
unsafe
/// Utility function to test the current system architecture.
///
/// Vectorscan requires the Supplemental Streaming SIMD Extensions 3 instruction
/// set. This function can be called on any x86 platform to determine if the
/// system provides the required instruction set.
///
/// This function does not test for more advanced features if Vectorscan has
/// been built for a more specific architecture, for example the AVX2
/// instruction set.
///
/// Returns [`ArchError`](error::VectorscanRuntimeError::ArchError) if system
/// does not support Vectorscan.
///
/// # Dependency on `"compiler"` Feature
/// This method is not available in the `hs_runtime` library for some reason, so
/// it currently cannot be provided without enabling the `"compiler"` feature.
///
///```
/// # fn main() -> Result<(), vectorscan::error::VectorscanRuntimeError> {
/// vectorscan::check_valid_platform()?;
/// # Ok(())
/// # }
/// ```
/// Utility function for identifying this release version.
///
/// Returns a string containing the version number of this release build and the
/// date of the build. It is allocated statically, so it does not need to
/// be freed by the caller.
///
///```
/// let v = vectorscan::vectorscan_version().to_str().unwrap();
/// assert!(v.starts_with("5.4.11 "));
/// ```
/// Utility function for identifying this release version.
///
/// Returns a string containing the version number of this release build and the
/// date of the build. It is allocated statically, so it does not need to
/// be freed by the caller.
///
///```
/// let v = vectorscan::chimera_version().to_str().unwrap();
/// assert!(v.starts_with("5.4.11 "));
/// ```