Trait aob::Needle

source ·
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());

Required Methods§

source

fn find_iter<'needle, 'haystack>( &'needle self, haystack: &'haystack [u8], ) -> Find<'needle, 'haystack>

Finds all matching subsequences, iteratively.

source

fn len(&self) -> usize

The length of the needle itself.

let needle = DynamicNeedle::from_ida("12 ? 56 ? 9A BC").unwrap();
assert_eq!(needle.len(), 6);

Provided Methods§

source

fn find<'haystack>(&self, haystack: &'haystack [u8]) -> Option<Match<'haystack>>

A convenience method for getting only the first match.

Implementors§

source§

impl Needle for DynamicNeedle

source§

impl<const NEEDLE_LEN: usize, const BUFFER_LEN: usize> Needle for StaticNeedle<NEEDLE_LEN, BUFFER_LEN>