pub const fn rfind_keep<'a, 'p, P>(this: &'a str, needle: P) -> Option<&'a str>where
P: Pattern<'p>,
Expand description
Truncates this
to the last instance of needle
.
Returns None
if no instance of needle
is found.
Returns Some(this)
if needle
is empty.
This takes Pattern
implementors as the needle.
ยงExample
use konst::string;
{
const FOUND: Option<&str> = string::rfind_keep("foo bar _ bar baz", '_');
assert_eq!(FOUND, Some("foo bar _"));
}
{
const FOUND: Option<&str> = string::rfind_keep("foo bar _ bar baz", "bar");
assert_eq!(FOUND, Some("foo bar _ bar"));
}
{
const NOT_FOUND: Option<&str> = string::rfind_keep("foo bar baz", "qux");
assert_eq!(NOT_FOUND, None);
}