pub const fn bytes_find(left: &[u8], right: &[u8], from: usize) -> Option<usize>
Expand description
Finds the byte offset of right
in left
, starting from the from
index.
Returns None
if right
isn’t inside &left[from..]
§Example
use konst::slice::bytes_find;
assert_eq!(bytes_find(b"foo-bar-baz-foo", b"foo", 0), Some(0));
assert_eq!(bytes_find(b"foo-bar-baz-foo", b"foo", 4), Some(12));
assert_eq!(bytes_find(b"foo-bar-baz-foo-bar", b"bar", 0), Some(4));
assert_eq!(bytes_find(b"foo-bar-baz-foo-bar", b"bar", 4), Some(4));
assert_eq!(bytes_find(b"foo-bar-baz-foo-bar", b"bar", 5), Some(16));
assert_eq!(bytes_find(b"foo-bar-baz-foo-bar", b"bar", 16), Some(16));
assert_eq!(bytes_find(b"foo-bar-baz-foo-bar", b"bar", 17), None);