pub const fn find_keep<'a>(this: &'a str, needle: &str) -> Option<&'a str>
Expand description
Advances this
up to the first instance of needle
.
Return None
if no instance of needle
is found.
Return Some(this)
if needle
is empty.
§Motivation
This function exists because calling find
+ str_from
when the "rust_1_64"
feature is disabled
is slower than it could be, since the slice has to be traversed twice.
§Example
use konst::string;
{
const FOUND: Option<&str> = string::find_keep("foo bar baz", "bar");
assert_eq!(FOUND, Some("bar baz"));
}
{
const NOT_FOUND: Option<&str> = string::find_keep("foo bar baz", "qux");
assert_eq!(NOT_FOUND, None);
}
{
const EMPTY_NEEDLE: Option<&str> = string::find_keep("foo bar baz", "");
assert_eq!(EMPTY_NEEDLE, Some("foo bar baz"));
}