Skip to content

Commit

Permalink
sl-std: Make ascii::Str::split_once use patterns
Browse files Browse the repository at this point in the history
This is for consistency, since the api was designed
before we had patterns
  • Loading branch information
simonwuelker committed Jun 30, 2024
1 parent 763b132 commit 61be8cd
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions crates/sl-std/src/ascii/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,10 +395,13 @@ impl Str {

#[inline]
#[must_use]
pub fn split_once(&self, split_at: Char) -> Option<(&Self, &Self)> {
let split_index = self.find(split_at)?;
let parts = (&self[..split_index], &self[split_index + 1..]);
Some(parts)
pub fn split_once<'a, P>(&'a self, delimiter: P) -> Option<(&Self, &Self)>
where
P: Pattern<'a>,
P::Searcher: Searcher<'a>,
{
let (start, end) = delimiter.into_searcher(self).next_match()?;
Some((&self[..start], &self[end..]))
}

/// Splits the string on the last occurrence of the specified delimiter and
Expand Down

0 comments on commit 61be8cd

Please sign in to comment.