2024-08-31 02:13:23 +00:00
|
|
|
use super::EMPTY;
|
|
|
|
|
|
|
|
|
|
type Pair<'a> = (&'a str, &'a str);
|
|
|
|
|
|
|
|
|
|
/// Split a string with default behaviors on non-match.
|
|
|
|
|
pub trait SplitInfallible<'a> {
|
|
|
|
|
/// Split a string at the first occurrence of delim. If not found, the
|
|
|
|
|
/// entire string is returned in \[0\], while \[1\] is empty.
|
|
|
|
|
fn split_once_infallible(&self, delim: &str) -> Pair<'a>;
|
|
|
|
|
|
|
|
|
|
/// Split a string from the last occurrence of delim. If not found, the
|
|
|
|
|
/// entire string is returned in \[0\], while \[1\] is empty.
|
|
|
|
|
fn rsplit_once_infallible(&self, delim: &str) -> Pair<'a>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'a> SplitInfallible<'a> for &'a str {
|
|
|
|
|
#[inline]
|
2024-12-15 00:05:47 -05:00
|
|
|
fn rsplit_once_infallible(&self, delim: &str) -> Pair<'a> {
|
|
|
|
|
self.rsplit_once(delim).unwrap_or((self, EMPTY))
|
|
|
|
|
}
|
2024-08-31 02:13:23 +00:00
|
|
|
|
|
|
|
|
#[inline]
|
2024-12-15 00:05:47 -05:00
|
|
|
fn split_once_infallible(&self, delim: &str) -> Pair<'a> {
|
|
|
|
|
self.split_once(delim).unwrap_or((self, EMPTY))
|
|
|
|
|
}
|
2024-08-31 02:13:23 +00:00
|
|
|
}
|