Function konst::slice::bytes_find_keep

source ·
pub const fn bytes_find_keep<'a, const N: usize, P>(
    this: &'a [u8],
    needle: &P
) -> Option<&'a [u8]>
where P: ?Sized + BytesPattern<N>,
Expand description

Advances this up to the first instance of needle.

Return None if no instance of needle is found.

Return Some(this) if needle is empty.

§Example

use konst::slice::bytes_find_keep;

{
    const FOUND: Option<&[u8]> = bytes_find_keep(b"foo bar baz", b"bar");
    assert_eq!(FOUND, Some(&b"bar baz"[..]));
}
{
    const NOT_FOUND: Option<&[u8]> = bytes_find_keep(b"foo bar baz", &'q');
    assert_eq!(NOT_FOUND, None);
}
{
    const EMPTY_NEEDLE: Option<&[u8]> = bytes_find_keep(b"foo bar baz", "");
    assert_eq!(EMPTY_NEEDLE, Some(&b"foo bar baz"[..]));
}