Function swift_check::search

source ·
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 search
  • cond - The condition to find the first occurrence of

§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 {
    panic!("input contained a 5");
}