Function memchr::memrchr2[][src]

pub fn memrchr2(needle1: u8, needle2: u8, haystack: &[u8]) -> Option<usize>
Expand description

Like memrchr, but searches for either of two bytes instead of just one.

This returns the index corresponding to the last occurrence of needle1 or the last occurrence of needle2 in haystack (whichever occurs later), or None if neither one is found. If an index is returned, it is guaranteed to be less than usize::MAX.

While this is operationally the same as something like haystack.iter().rposition(|&b| b == needle1 || b == needle2), memrchr2 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 last position of either of two bytes in a byte string.

use memchr::memrchr2;

let haystack = b"the quick brown fox";
assert_eq!(memrchr2(b'k', b'q', haystack), Some(8));