memmem/lib.rs
1// Copyright 2015 Joe Neeman
2//
3// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6// option. This file may not be copied, modified, or distributed
7// except according to those terms.
8
9/*!
10A crate for string searching. The main trait is `Searcher`, which has a function for finding fixed
11things in long byte-strings. Currently, the only implementer of `Searcher` is `TwoWaySearcher`.
12
13# Example
14
15```rust
16use memmem::{Searcher, TwoWaySearcher};
17let search = TwoWaySearcher::new("dog".as_bytes());
18assert_eq!(search.search_in("The quick brown fox jumped over the lazy dog.".as_bytes()), Some(41));
19```
20*/
21
22mod two_way;
23
24pub use two_way::TwoWaySearcher;
25
26/// A trait that searches for patterns in byte-strings.
27pub trait Searcher {
28 /// Search for something in a byte-string. Returns the starting index of the match, if found.
29 fn search_in(&self, haystack: &[u8]) -> Option<usize>;
30}