Function konst::string::strip_prefix

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

A const subset of str::strip_prefix.

This takes Pattern implementors as the pattern.

§Example

use konst::string;

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

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