pub trait Needle: Sealed {
// Required methods
fn find_iter<'needle, 'haystack>(
&'needle self,
haystack: &'haystack [u8],
) -> Find<'needle, 'haystack> ⓘ;
fn len(&self) -> usize;
// Provided method
fn find<'haystack>(
&self,
haystack: &'haystack [u8],
) -> Option<Match<'haystack>> { ... }
}
Expand description
The common interface for searching haystacks with needles.
A successful search will yield a Match
in the haystack, whose length is equal to the length of the needle. Matches may overlap.
let needle = DynamicNeedle::from_ida("12 23 ? 12").unwrap();
let haystack = [0x32, 0x21, 0x12, 0x23, 0xAB, 0x12, 0x23, 0xCD, 0x12];
let mut iter = needle.find_iter(&haystack);
assert_eq!(&haystack[iter.next().unwrap().start()..], [0x12, 0x23, 0xAB, 0x12, 0x23, 0xCD, 0x12]);
assert_eq!(&haystack[iter.next().unwrap().start()..], [0x12, 0x23, 0xCD, 0x12]);
assert!(iter.next().is_none());