aho-corasick
Fast multiple substring searching.
This package has a good security score with no known vulnerabilities.
Community Reviews
Battle-tested substring matching with zero runtime surprises
The builder pattern offers good control over memory/speed tradeoffs through different implementations (NFA, DFA, contiguous DFA). The library handles UTF-8 boundaries correctly by default, which prevents a whole class of bugs. Error handling is minimal because there's not much that can go wrong - pattern compilation is infallible, and searches return iterators.
Resource management is clean: no connection pooling needed, automaton instances are Send+Sync so sharing across threads is trivial. The main gotcha is forgetting that construction cost matters for small pattern sets - if you're only searching for 2-3 strings once, a simpler approach might be faster. For repeated searches or large pattern sets, this is the gold standard.
Best for: High-throughput text processing where you need to find multiple patterns repeatedly, like log analysis, content filtering, or security scanning.
Avoid if: You're doing single-shot searches with small pattern counts where simple string methods would suffice.
Rock-solid string matching with excellent security properties
Input validation is implicit through Rust's type system - patterns and haystacks are just byte slices, with no special parsing that could introduce injection risks. Error handling is minimal because the algorithm itself is infallible once constructed; the only errors come from builder validation, which provides clear messages without leaking internal state. Memory usage is predictable and bounded by your pattern set, not by input size.
From a supply chain perspective, this is low-risk: maintained by the regex crate author (BurntSushi), minimal dependencies, and straightforward code that's easy to audit. The crate has seen consistent maintenance and bug fixes without breaking changes. I've used it in production for log filtering and content scanning without security concerns.
Best for: High-performance pattern matching in security-sensitive contexts like WAF rules, log analysis, or content filtering where DoS resistance matters.
Avoid if: You need fuzzy matching, regex features, or Unicode-aware operations beyond simple byte sequence detection.
Blazingly fast and refreshingly simple to use
Error messages are helpful when you make mistakes, like forgetting to handle the case where no matches are found. The library provides multiple search methods (find, find_iter, stream searching) that cover common use cases well. Performance is excellent - I've used it for log parsing and content filtering where it outperformed naive approaches by orders of magnitude.
The main learning curve is understanding when to use DFA vs NFA implementations, but the docs explain the tradeoffs clearly. The crate is stable, well-maintained, and the author (BurntSushi) is responsive to issues. Stream searching support makes it particularly useful for large file processing.
Best for: Projects needing fast multi-pattern string matching like log parsing, content filtering, or text processing pipelines.
Avoid if: You only need single-pattern matching where String::find() or regex would be simpler.
Sign in to write a review
Sign In