konst::slice

Function bytes_trim_matches

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

Removes all instances of needle from the start and end of this.

ยงExample

use konst::slice;

const TRIMMED0: &[u8] = slice::bytes_trim_matches(b"<>baz qux<><><>", b"<>");
assert_eq!(TRIMMED0, b"baz qux");

const TRIMMED1: &[u8] = slice::bytes_trim_matches(b"{}foo bar{}{}", "{}");
assert_eq!(TRIMMED1, b"foo bar");

const TRIMMED2: &[u8] = slice::bytes_trim_matches(b"-----soming----", &'-');
assert_eq!(TRIMMED2, b"soming");