Function konst::string::split_once
source · pub const fn split_once<'a, 'p, P>(
this: &'a str,
delim: P,
) -> Option<(&'a str, &'a str)>where
P: Pattern<'p>,
Expand description
A const-equivalent of the str::split_once
method.
This takes Pattern
implementors as the delimiter.
§Example
use konst::string;
assert_eq!(string::split_once("", "-"), None);
assert_eq!(string::split_once("foo", "-"), None);
assert_eq!(string::split_once("foo-", "-"), Some(("foo", "")));
assert_eq!(string::split_once("foo-bar", "-"), Some(("foo", "bar")));
assert_eq!(string::split_once("foo-bar-baz", "-"), Some(("foo", "bar-baz")));
assert_eq!(string::split_once("foo,bar", ","), Some(("foo", "bar")));
assert_eq!(string::split_once("foo,bar,baz", ","), Some(("foo", "bar,baz")));