teddy/lib.rs
1//! This crate contains two types: `Teddy` is the main one. You create one by passing in a set of
2//! patterns. It does some preprocessing, and then you can use it to quickly search for those
3//! patterns in some text. Searching returns a `Match`, which will tell you which of the patterns
4//! matched and where.
5//!
6//! ```
7//! use teddy::{Match, Teddy};
8//!
9//! let patterns = vec![b"cat", b"dog", b"fox"];
10//! let ted = Teddy::new(patterns.iter().map(|s| &s[..])).unwrap();
11//! assert_eq!(
12//! Some(Match { pat: 2, start: 16, end: 19 }),
13//! ted.find(b"The quick brown fox jumped over the laxy dog.")
14//! );
15//! ```
16
17#![cfg_attr(feature="simd-accel", feature(asm, associated_consts, cfg_target_feature, platform_intrinsics))]
18
19extern crate aho_corasick;
20#[cfg(feature="simd-accel")]
21extern crate simd;
22
23#[cfg(test)]
24#[macro_use]
25extern crate quickcheck;
26
27#[cfg(all(feature="simd-accel", any(target_feature="sse3", target_feature="avx2")))]
28mod x86;
29#[cfg(all(feature="simd-accel", any(target_feature="sse3", target_feature="avx2")))]
30pub use x86::Teddy;
31
32#[cfg(not(all(feature="simd-accel", any(target_feature="sse3", target_feature="avx2"))))]
33mod fallback;
34#[cfg(not(all(feature="simd-accel", any(target_feature="sse3", target_feature="avx2"))))]
35pub use fallback::Teddy;
36
37/// Match reports match information.
38#[derive(Debug, Clone, PartialEq)]
39pub struct Match {
40 /// The index of the pattern that matched. The index is in correspondence
41 /// with the order of the patterns given at construction.
42 pub pat: usize,
43 /// The start byte offset of the match.
44 pub start: usize,
45 /// The end byte offset of the match. This is always `start + pat.len()`.
46 pub end: usize,
47}
48