pub const fn split_at(string: &str, at: usize) -> (&str, &str)
Expand description
A const equivalent of str::split_at
If at > string.len()
this returns (string, "")
.
§Panics
This function panics if at
is inside the string but doesn’t fall on a char boundary.
§Example
use konst::string;
const IN: &str = "foo bar baz";
{
const SPLIT0: (&str, &str) = string::split_at(IN, 0);
assert_eq!(SPLIT0, ("", "foo bar baz"));
}
{
const SPLIT1: (&str, &str) = string::split_at(IN, 4);
assert_eq!(SPLIT1, ("foo ", "bar baz"));
}
{
const SPLIT2: (&str, &str) = string::split_at(IN, 8);
assert_eq!(SPLIT2, ("foo bar ", "baz"));
}
{
const SPLIT3: (&str, &str) = string::split_at(IN, 11);
assert_eq!(SPLIT3, ("foo bar baz", ""));
}
{
const SPLIT4: (&str, &str) = string::split_at(IN, 13);
assert_eq!(SPLIT4, ("foo bar baz", ""));
}