Function fastchr::fastchr[][src]

pub fn fastchr(needle: u8, haystack: &[u8]) -> Option<usize>

Returns the index corresponding to the first occurrence of needle in haystack, or None if one is not found.

fastchr is implemented using SIMD intrinsics and run-time CPU feature detection, so it is often faster than memchr due to being able to take advantage of available SIMD features at run-time.

Example

use fastchr::fastchr;
 
let haystack = b"the quick brown fox jumps over the lazy dog";
assert_eq!(fastchr(b'k', haystack), Some(8));
assert_eq!(fastchr(b'o', haystack), Some(12));
assert_eq!(fastchr(b'!', haystack), None);