pub const fn bytes_strip_suffix<'a, const N: usize, P>(
left: &'a [u8],
suffix: &P,
) -> Option<&'a [u8]>where
P: ?Sized + BytesPattern<N>,
Expand description
Remove suffix
from the end of left
.
Returns None
if suffix
is not the end of left
.
A const analog of
<[u8]>::strip_suffix
ยงExample
use konst::slice::bytes_strip_suffix;
assert_eq!(bytes_strip_suffix(b"foo,bar,baz", b",baz"), Some("foo,bar".as_bytes()));
assert_eq!(bytes_strip_suffix(b"foo,bar,baz", ",bar,baz"), Some("foo".as_bytes()));
assert_eq!(bytes_strip_suffix(b"foo,bar,baz", &'z'), Some("foo,bar,ba".as_bytes()));
assert_eq!(bytes_strip_suffix(b"foo,bar,baz", b"bar"), None);
assert_eq!(bytes_strip_suffix(b"foo,bar,baz", "foo"), None);