pub const fn bytes_rfind_skip<'a>(
this: &'a [u8],
needle: &[u8],
) -> Option<&'a [u8]>
Expand description
Truncates this
to before the last instance of needle
.
Return None
if no instance of needle
is found.
Return Some(this)
if needle
is empty.
§Motivation
This function exists because calling bytes_rfind
+ slice_up_to
when the "rust_1_64"
feature is disabled
is slower than it could be, since the slice has to be traversed twice.
§Example
use konst::slice::bytes_rfind_skip;
{
const FOUND: Option<&[u8]> = bytes_rfind_skip(b"foo bar _ bar baz", b"bar");
assert_eq!(FOUND, Some(&b"foo bar _ "[..]));
}
{
const NOT_FOUND: Option<&[u8]> = bytes_rfind_skip(b"foo bar baz", b"qux");
assert_eq!(NOT_FOUND, None);
}
{
const EMPTY_NEEDLE: Option<&[u8]> = bytes_rfind_skip(b"foo bar baz", b"");
assert_eq!(EMPTY_NEEDLE, Some(&b"foo bar baz"[..]));
}