pub fn search(data: &[u8], cond: impl Fn(Vector) -> Vector) -> Option<usize>
Expand description
Find the first byte that meets the cond
§Arguments
data
- The haystack to searchcond
- The condition to find the first occurrence of
§Returns
Some(position)
- The first position where the condition was met, this position will always be less thandata.len()
ensuring that indexing it will never panic. If you’re interested in further investigating this claim seearch/simd_scan.rs
.None
- There was no circumstance of the condition being met.
§Example
use swift_check::{search, eq};
let input = b"some data with a 5 burger 383294 hello world blah blah blah";
if let Some(pos) = search(input, eq(b'5')) {
assert_eq!(input[pos], b'5');
} else {
unreachable!("input contained a 5");
}