Function konst::string::strip_suffix

source ·
pub const fn strip_suffix<'a, 'p, P>(
    string: &'a str,
    pattern: P,
) -> Option<&'a str>
where P: Pattern<'p>,
Expand description

A const subset of str::strip_suffix.

This takes Pattern implementors as the pattern.

§Example

use konst::string;

{
    const STRIP: Option<&str> = string::strip_suffix("3 5 8--", '-');
    assert_eq!(STRIP, Some("3 5 8-"));
}
{
    const STRIP: Option<&str> = string::strip_suffix("3 5 8", '_');
    assert_eq!(STRIP, None);
}

{
    const STRIP: Option<&str> = string::strip_suffix("3 5 6868", "68");
    assert_eq!(STRIP, Some("3 5 68"));
}
{
    const STRIP: Option<&str> = string::strip_suffix("3 5 8", "hello");
    assert_eq!(STRIP, None);
}