Dual-licensed under MIT or the UNLICENSE.
The regex-automata
crate provides implementations of the fst::Automata
trait when its transducer
feature is enabled. This permits using DFAs compiled by regex-automata
to search finite state transducers produced by this crate.
Simply add a corresponding entry to your Cargo.toml
dependency list:
[dependencies] fst = "0.4"
This example demonstrates building a set in memory and executing a fuzzy query against it. You'll need fst = "0.4"
with the levenshtein
feature enabled in your Cargo.toml
.
use fst::{IntoStreamer, Set}; use fst::automaton::Levenshtein; fn main() -> Result<(), Box<dyn std::error::Error>> { // A convenient way to create sets in memory. let keys = vec!["fa", "fo", "fob", "focus", "foo", "food", "foul"]; let set = Set::from_iter(keys)?; // Build our fuzzy query. let lev = Levenshtein::new("foo", 1)?; // Apply our fuzzy query to the set we built. let stream = set.search(lev).into_stream(); let keys = stream.into_strs()?; assert_eq!(keys, vec!["fo", "fob", "foo", "food"]); Ok(()) }
Check out the documentation for a lot more examples!
levenshtein
- Disabled by default. This adds the Levenshtein
automaton to the automaton
sub-module. This includes an additional dependency on utf8-ranges
.