Function memchr::memchr2 [−][src]
Expand description
Like memchr
, but searches for either of two bytes instead of just one.
This returns the index corresponding to the first occurrence of needle1
or the first occurrence of needle2
in haystack
(whichever occurs
earlier), or None
if neither one is found.
While this is operationally the same as something like
haystack.iter().position(|&b| b == needle1 || b == needle2)
, memchr2
will use a highly optimized routine that can be up to an order of magnitude
faster in some cases.
Example
This shows how to find the first position of either of two bytes in a byte string.
use memchr::memchr2;
let haystack = b"the quick brown fox";
assert_eq!(memchr2(b'k', b'q', haystack), Some(4));